1.

import java.util.Scanner;

/**
* Angewandte Mathematik, SS11
* Problem: 160 Factors and Factorials
* Link: http://uva.onlinejudge.org/external/1/160.pdf
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 09/04/2011
*
* Method : schnelle Berechnung der Primfaktoren in einer Fakult¦t
* Status : Accepted
* Runtime: 0.148
*/

public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number;
int p;

while((number=sc.nextInt()) != 0)
{
int counter = 15;
System.out.format("%3d! =", number);
p = getPowerInFak(number, 2);
if(p != 0)
{
System.out.format("%3d", p);
counter--;
}

for(int i = 3; i<=number; i++)
{
if(isPrime(i))
{
p = getPowerInFak(number, i);
if(p != 0)
{
if(counter==0)
{
System.out.print("\n ");
counter = 15;
}
System.out.format("%3d", p);
counter--;
}
}
}
System.out.println();
}
}

/**
* Gibt an wie oft ein Faktor n in einer Fakult¦t fak vorkommt
* @param fak Fakult¦t
* @param n Faktor
* @return H¦ufigkeit des Faktors
*/
public static int getPowerInFak(int fak, int n)
{
int power = 0;
for (int div = n; n <= div ; div *= n)
{
power += fak/div;
}
return power;
}

/**
* Bestimmt ob eine ganze Zahl eine Primzahl ist. (schleifen-l¨sung)
* @param n ganze zahl
* @return true wenn n eine Primzahl ist, sonst false
*/
public static boolean isPrime(int n)
{
if(n == 2)
{
return true;
}
else if(n < 2 || n%2==0)
{
return false;
}
for(int i = 3; i <= java.lang.Math.sqrt(n); i+=2)
{
if(n%i==0)
{
return false;
}
}
return true;
}
}


--------------------------------------------------------------
1.
/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: Math: Primes
* Problem: 160 - FactorsAndFactorials
* Accepted: 0.004
* @author Evgeni Pavlidis
*
*/
import java.io.*;
import java.util.*;

class Main {


public static final int MAX = 100;
public static int[] prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
public static final int[][] cache = new int[MAX+1][25];


private static void findPrimes(int f)
{
int power, divisor, p;

for(int i = 0; i < prime.length; i++)
{
p = prime[i];
power = 0;
divisor = 1;

do
{
divisor *= p;
power += f / divisor;
}
while( f / (divisor*p) > 0);
cache[f][i] = power;
}

}

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuffer output = new StringBuffer();
String input;
int n, c;

for(int i=2; i <= MAX; i++)
findPrimes(i);


while( (input = reader.readLine()) != null )
{
n = Integer.parseInt(input);
if(n == 0)
break;

c = 0;

output.append(String.format("%3d! =",n));
for(int i=0; i < prime.length; i++)
if(cache[n][i] > 0)
{
c++;
if(c > 15)
{
output.append("\n ");
c = 0;
}

output.append(String.format(" %2d",cache[n][i]));

}
output.append("\n");
}
System.out.print(output.toString());

}
}