2935 - Python Brute Force

Created by Frank Arteaga Salgado
Added by frankr (2014-06-08)
Limits
Total Time: 50000 MS | Test Time: 8000 MS |Memory: 62 MB | Output: 64 MB | Size: 14 KB
Enabled languages
Available in

Description

Mr. Reni likes programming in Python language for solving or exploring the nature of math challenge. Python allows him to quickly write a brute force method and then test his conjectures. But this approach can sometimes be ineffective; however it may still be useful to test a better solution.

In this problem you have to write a program to calculate the number of digits of an integer S(N) in some base B where S(N) is given by:

S(N) = 1*1! + 2*2! + 3*3! + ... + N*N!

and let Mr. Reni codify the Brute Force in Python for you.

Note: K! means factorial(K) = 1 * 2 * 3 * ... * K.
Mr. Reni likes programming in Python language for solving or exploring the nature of math challenge. Python allows him to quickly write a brute force method and then test his conjectures. But this approach can sometimes be ineffective; however it may still be useful to test a better solution.

In this problem you have to write a program to calculate the number of digits of an integer S(N) in some base B where S(N) is given by:

S(N) = 1*1! + 2*2! + 3*3! + ... + N*N!

and let Mr. Reni codify the Brute Force in Python for you.

Note: K! means factorial(K) = 1 * 2 * 3 * ... * K.
Mr. Reni likes programming in Python language for solving or exploring the nature of math challenge. Python allows him to quickly write a brute force method and then test his conjectures. But this approach can sometimes be ineffective; however it may still be useful to test a better solution.

In this problem you have to write a program to calculate the number of digits of an integer S(N) in some base B where S(N) is given by:

S(N) = 1*1! + 2*2! + 3*3! + ... + N*N!

and let Mr. Reni codify the Brute Force in Python for you.

Note: K! means factorial(K) = 1 * 2 * 3 * ... * K.

Input specification

The first line of input contains an integer T (1 <= T <= 10^4), the number of test cases. Each test case contains two integers N and B (1 <= N <= 10^6; 2 <= B <= 10).
The first line of input contains an integer T (1 <= T <= 10^4), the number of test cases. Each test case contains two integers N and B (1 <= N <= 10^6; 2 <= B <= 10).
The first line of input contains an integer T (1 <= T <= 10^4), the number of test cases. Each test case contains two integers N and B (1 <= N <= 10^6; 2 <= B <= 10).

Output specification

For each pair N and B in the input you must print the number of digits of S(N) in base B.
For each pair N and B in the input you must print the number of digits of S(N) in base B.
The first line of input contains an integer T (1 <= T <= 10^4), the number of test cases. Each test case contains two integers N and B (1 <= N <= 10^6; 2 <= B <= 10).

Sample input

3
3 4
2 2
3 10

Sample output

3
3
2

Hint(s)