1.


import java.math.BigInteger;
import java.util.Scanner;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: ##324## Factorial Frequencies
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=260
*
* @author Felix Dietrich
* @version 1.0, 14.10.2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.556
*/

public class Main
{
public static void main(String... strings)
{
Scanner sc = new Scanner(System.in);

BigInteger b = BigInteger.valueOf(1);
int[][] digits = new int[366][10];
int d = 0;
String s;

for(int i=0; i<366; i++)
{
b = b.multiply(BigInteger.valueOf(i+1));

s = b.toString();
for(int k=0; k<s.length(); k++)
{
d = Integer.parseInt(String.valueOf(s.charAt(k)));
digits[i][d]++;
}
}

while(sc.hasNext())
{
int num = sc.nextInt();
if(num == 0)
return;

System.out.println(String.format("%d! --", num));
for(int dig=0; dig<10; dig++)
{
System.out.print(String.format("(%d) %d ", dig, digits[num-1][dig]));
if(dig == 4)
System.out.println();
}
System.out.println();
}
}
}



2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 324 - Factorial Frequencies
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=260
*
* @author Felix Dietrich
* @version 1.0, 06/08/2010
*
* Method : BigInteger
* Status : accepted
* Runtime: 0.220
*/


import java.util.*;
import java.lang.*;
import java.math.*;

class Main
{
public static BigInteger[] store = new BigInteger[380];

public static void calcStore()
{
BigInteger result;
for(int n=1; n<store.length; n++)
{
result = BigInteger.ONE;
for(int i=1; i<=n; i++)
result = result.multiply(BigInteger.valueOf(i));
store[n] = result;
}
}

public static int[] countDigits(BigInteger b)
{
int[] result = new int[10];

String b_str = b.toString();
for(char c: b_str.toCharArray())
result[c-'0']++;

return result;
}

public static void main(String... args)
{
calcStore();

Scanner sc = new Scanner(System.in);

int n;
int[] digits;
BigInteger result;
while(sc.hasNext())
{
n = sc.nextInt();
if(n == 0)
return;

System.out.println(n + "! --");
digits = countDigits(store[n]);
for(int i=0; i<=4; i++)
System.out.printf(" (%d) %d", i, digits[i]);
System.out.println();
for(int i=5; i<=9; i++)
System.out.printf(" (%d) %d", i, digits[i]);
System.out.println();
}
}
}