It is very easy to find number of trailing zero in n! for a particular base b. In this problem you have to do the reverse. You have to find for how many bases b, n! has k trailing zeros in base b.
Input
Input starts with a positive number T≤10000, denoting the number of test cases to follow.
Each test case contains two non-negative integers, n≤1015 and 1≤k≤1015 in a line. You may assume and n/k<500. Output
For each input output one line containing the number of different bases. Print the solution modulo 1000000007
Sample Input
1
2
3
4
5
6
5
10 2
10 3
10 4
10 5
10 8
Sample Output
1
2
3
4
5
Case 1: 24
Case 2: 0
Case 3: 4
Case 4: 0
Case 5: 1
Solution
題目描述:
對於 n! 的 b 進制數中,尾數恰好為 k 個 0 情況為何?
題目解法:
質因數分解,找到每一個質數的次方數,根據數學組合和排容原理得到,大於等於 k 個 0 的基底情況個數為何,因此
對於 2^n1 * 3^n2 * 5^n3 * 7^n4 ... = n!,
base = pi^mi * ...,保證 (pi^mi)^k => mi * k <= ni。計算 mi (0, 1, …, ni/k)的可能情況總數乘積即可。