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
1000000
Sample Output
1
1
130271
5565709
log10(x)就是求x的十进制位数,log(x)就是求x的二进制位数
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int n;
while(~scanf("%d", &n))
{ double ans = 1.0;
for(int i = 1; i <= n; i++)
ans += log10(i*1.0); // 里面要乘一个1.0把int转化为double型,不然会WA
printf("%d\n", (int)ans);
}
}