FZU -1050
Accept: 1102 Submit: 2275
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead of calculating N!, I want to know how many digits are in it. (Remember that N! = N * (N - 1) * (N - 2) * … * 2 * 1)
Input
Each line of the input will have a single integer N on it 0 < N < 1000000 (1 million). Input is terminated by end of file.
Output
For each value of N, print out how many digits are in N!.
Sample Input
1
3
32000
Sample Output
1
1
130271
注:中国好伙伴
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int n;
while(~scanf("%d",&n))
{
double k=0;
for(int i=n;i>=1;i--)
{
k+=log10(i*1.0);//计算位数
}
printf("%d\n",int(k+1));
}
return 0;
}