Zeroes III

Thefactorialn! ofanumbernisdefinedasn!=1∗2∗3∗...∗n. The function F1(n) = 1!∗2!∗3!∗ . . . ∗ n! And the function F2(n) = F1(1) ∗ F1(2) ∗ F1(3) ∗ . . . ∗ F1(n) Given two numbers n and b your job is to find the number of trailing zeroes in F2(n) when expressed in base b. Input The input file contains around 2000 lines of inputs. Each line contains two integers n (1 ≤ n ≤ 1000000) and b (2 ≤ b ≤ 10000). Input is terminated by a line containing two zeroes. Output For each line of input produce one line of output which contains an integer Z, which denotes the number of trailing zeroes in F2(n), when expressed in base b. Sample Input 10 3 42 00 Sample Output 57 8