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[sup]7[/sup] 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的阶乘的位数。
首先我们思考一下log10(23),101=10,102=100,log10(23)一定在1和2之间,将他向下取整后再+1就是23的位数。
现在再来看N!的位数,也就是(int)log10(N(N-1)(N-2)…1)+1==(int)(log10(N)+log10(N-1)+…+log10(1))+1
C
#include <stdio.h>
#include <math.h>
#pragma warning(disable:4996)
int main(void)
{
int i,n,digit;
double sum=0;
scanf("%d",&n);
while(n--)
{
scanf("%d",&digit);
for(sum=0,i=1;i<=digit;i++)
sum+=log10(i);
printf("%d\n",(int)sum+1);
}
return 0;
}