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 ≤ 107 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
题意:先输入T,之后输入T组数据N,求每组数据N!的位数
分析:因为N!=1*2*3....*N,那么我们求位数的时候取个对数就行了,
即 log10(N!)=log10(1)+ log10(2) +log10(3)...+log10(N),于是就变成了循环求和问题。这里要注意的是log10(1) = 0,而实际上我们
要的是log10(1!) = 0!,因此要加上这个误差。
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
int cas,ans,i,n;
double sum;
cin>>cas;
while(cas--){
scanf("%d",&n);
sum=1;
for(i=1;i<=n;i++)
sum+=log10(i);
printf("%d\n",((int)sum));
}
return 0;
}