In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.
Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
21020
Sample Output
719
题意
求出\(n!\)有几位数。
思路
我们考虑用log解决。
\(log_{10}ab=log_{10}a+log_{10}b\)
因此\(log_{10}n!=log_{10}1+log_{10}2+……+log_{10}n\)
\(floor(log_{10}n!)+1\)即为\(n!\)的位数。
代码
#includeusing namespace std;#define Re register#define MAXN 10000005#define LD long doubleint f[MAXN];LD c;int n, t;int main(){ for ( int i = 1; i <= 10000000; ++i ){ c += log10(i); f[i] = (int)floor(c) + 1; } scanf( "%d", &n ); while( n-- ){ scanf( "%d", &t ); printf( "%d\n", f[t] ); } return 0;}