Problem Description
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 ≤ 10
7 on each line.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
2 10 20
Sample Output
7 19
意思很简单 就是求输入n的这个数字的阶乘有几位数
尝试过用大数阶乘来做 先乘再求位数 发现超时
那么也就是只能用数学方法
寻找了一下发现 lg(6*5*4*3*2)=lg6+lg5+lg4+lg3+lg2近似于6的阶乘的位数-1
#include<stdio.h>
#include<math.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,n;
double sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
sum+=log10(i);
printf("%d\n",(int)sum+1);
}
return 0;
}