Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30896 Accepted Submission(s): 14313
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 ≤ 10
7 on each line.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
Sample Output
Source
Asia 2002, Dhaka (Bengal)
Recommend
JGShining | We have carefully selected several similar problems for you: 1013 1017 1071 1008 1061
Statistic | Submit | Discuss | Note
敢想 敢写 就A了0.0
既然问某个数的阶乘有多少位
我们先拆开看看。如果问某个数n有几位。直接log10(n)就是结果了。既然问某个数的阶乘
也是一样的道理。log10(1*2*3*4*....*n),当然我们是不会让它乘这么多的 因为log10(a)+long10(b)=log10(a*b);
OK,看代码:
#include <stdio.h>
#include <math.h>
int main()
{
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
int n;
double sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
sum+=log10(i);
printf("%d\n",(int)sum+1);
}
return 0;
}