Number lengths 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 /* n!=1*2*3*....*n → lg(n!)=lg(1*2*3*....*n)=lg(1)+lg(2)+ lg(3)+..+lg(n) → n!=10^(lg(1)+lg(2)+ lg(3)+..+lg(n)) */ #include<iostream> #include<cmath> using namespace std; int main() { long n,i; double sum; long temp; while(scanf("%d",&n)!=EOF) { sum=0.0; for(i=1;i<=n;i++)sum+=log10((double)i); temp=long(sum+1); cout<<temp<<endl; } return 0; }

评论