In many applications very large integers numbers are required. Some of theseapplications 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 digitsin the factorial of the number.
Input
Input consists of several lines of integer numbers. The first line contains anintegern, which is the number of cases to be tested, followed byn lines,one integer 1 n
107 on each line.
Output
The output contains the number of digits in the factorial of the integers appearingin the input.
Sample Input
2 10 20
Sample Output
7 19题意:给出一个数,求其阶乘的结果有多少位
思路:
#include <stdio.h>
#include <math.h>
int n;
void input()
{
scanf("%d", &n);
}
void solve()
{
double ans = 0;
if (n == 1) {
printf("1\n");
return;
}
for (int i = n; i >= 1; i--) {
ans += log10((double)i);
}
printf("%d\n", (int)ceil(ans));
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif
int cas;
scanf("%d", &cas);
while (cas--) {
input();
solve();
}
return 0;
}