1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10061 How many zero's and how many digits ?
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1002
*
* @author Anton Pavlushko, IBB7B,
* @version 1.0, 10/10/2010
*
* Status : Accepted
* Runtime: 0.300
*/

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String current_line, empty = "";
long number, factorial, i, j, length, number_local, count;
long primes [], counts [];
long znak,count5,count5_already,multiply;
StringTokenizer input_string;
boolean status, at_least_one;
double try_it, base_log;
Map<Integer,Integer> mp_number=new HashMap<Integer,Integer>();
Map<Integer,Integer> mp_factorial=new HashMap<Integer,Integer>();

try {
while ((current_line=in.readLine())!= null && !current_line.equals("0")) {
input_string = new StringTokenizer(current_line);
factorial = Integer.parseInt(input_string.nextToken());
number = Integer.parseInt(input_string.nextToken());

if (!mp_number.isEmpty()) mp_number.clear();
if (!mp_factorial.isEmpty()) mp_factorial.clear();

number_local=number;
length=number_local/2+1;
at_least_one=false;
for(j=2;j<=length;j++) {
count=0;
while(number_local%j==0) {
number_local=number_local/j;
count++;
}

if (count>0) {
mp_number.put((int)j,(int)count);
at_least_one=true;
}

if (number_local==1) break;
}

if (at_least_one==false) {
mp_number.put((int)number_local,1);
}//it was prime

count=0;
for(Map.Entry<Integer,Integer> entry : mp_number.entrySet()) {
count=Math.max(count,entry.getValue());
// System.out.println(entry.getKey()+" - "+entry.getValue());
}
// System.out.println(count);

count=0;
for(Map.Entry<Integer,Integer> entry : mp_number.entrySet()) {

znak=(int)Math.floor(Math.log10(factorial)/Math.log10(entry.getKey()));
if (factorial<=Math.pow(entry.getKey(),znak+1)) znak++; //2.999999999996 Problem...

count5=0;
// System.out.println(znak+" : "+entry.getValue());
for(i=1;i<=znak;i++) {
count5_already=(int)Math.floor(factorial/Math.pow(entry.getKey(),i));
count5+=count5_already;
}

mp_factorial.put((int)entry.getKey(),(int)count5);

count=Math.max(count,count5);
// System.out.println(entry.getKey()+" - "+mp_factorial.get(entry.getKey()));
}

for(Map.Entry<Integer,Integer> entry : mp_number.entrySet()) {
if (!mp_factorial.containsKey(entry.getKey())) {
count=0;
break;
}else{
// System.out.println(entry.getKey()+" - "+mp_factorial.get(entry.getKey())/entry.getValue());
count=Math.min(count,mp_factorial.get(entry.getKey())/entry.getValue());
}
}

if (true) {
try_it=0;
base_log=Math.log10(number);
for(j=2;j<=factorial;j++) {
try_it+=Math.log10(j)/base_log;
}
i=(int)Math.floor(try_it)+1;
} else if (false) {
try_it=Math.log10(Math.sqrt(2))/Math.log10(number)+0.00000001;
try_it+=Math.log10(Math.sqrt(Math.PI))/Math.log10(number)+0.00000001;
try_it+=Math.log10(Math.sqrt(factorial))/Math.log10(number)+0.00000001;
try_it+=factorial*(Math.log10(factorial/Math.E)/Math.log10(number)+0.00000001);
i=(int)Math.floor(try_it)+1;
}//Stirling...


System.out.println(count+" "+i);
} // end while
} // end try
catch (IOException e) {
System.err.println("Error: " + e);
}
}
}


2.

/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: Math: Primes
* Problem: 10061 - HowManyZeros
* Accepted: 0.256
* @author Evgeni Pavlidis

*/
import java.io.*;
import java.util.*;

class Main {


public static final int MAX = 800;
public static final int[][] primeDivisor = new int[MAX+1][5];
public static final int[][] primePower = new int[MAX+1][5];
public static final int[] index = new int[MAX+1];


private static void findBaseDivisors()
{
int power,d;
// sieve the multiples of 2
for(int i = 2; i <= MAX; i+=2)
{
d = 2;
power = 1;
while((i % (d*2)) == 0)
{
d *= 2;
power++;
}
primePower[i][index[i]] = power;
primeDivisor[i][index[i]++] = 2;
}

// sieve other numbers
for(int i = 3; i <= MAX; i+=2)
if(index[i] == 0)
for(int j = i; j <= MAX; j += i)
{
d = i;
power = 1;
while(j % (d*i) == 0)
{
d *= i;
power++;
}
primePower[j][index[j]] = power;
primeDivisor[j][index[j]++] = i;
}

/** /
for(int i = 1; i <= MAX; i++)
for(int j=0; j < index[i]; j++)
System.out.println(i + " += " + primeDivisor[i][j]+"^" + primePower[i][j]);
/**/
}

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);

int n,b, digits, min, power = 0;
long divisor;

findBaseDivisors();

while( scanner.hasNextInt() )
{
n = scanner.nextInt();
b = scanner.nextInt();
double digitsLogs = 0;

min = Integer.MAX_VALUE;

// calculate zeros
if(n == 0)
min = 0;
else
for(int i = 0; i < index[b]; i++)
{
power = 0;
divisor = 1;

do
{

divisor *= primeDivisor[b][i];
//System.out.println(" " + n + " " + divisor + " ==> " + n/divisor + " " + power);
power += n / divisor;
}
while( n / (divisor*primeDivisor[b][i]) > 0);

//System.out.println(" ---- " + power + " " + primePower[b][i]);


power = power / primePower[b][i];

if(power < min)
min = power;
}

for(int i = 2; i <= n; i++)
digitsLogs += Math.log(i);
digits = (int)Math.floor(digitsLogs/Math.log(b) + 1);

System.out.println(((min < 0)? 0:min) + " " + digits);
}
}
}