1. 

/**
* 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);
}
}
}