`

杭电 1018

阅读更多
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

Source

Asia 2002, Dhaka (Bengal) 


这一题运用了一个数学公式,叫做斯格拉公式,可以自己查询了解一下这个公式,我当时做这个题时,当阶乘后数字大于9时,显示的结果总是少1,自己调了好久,感觉那都没有错,结果就是不对,最后一次就把数字分数形式换成了小数形式,因为1/2==0,在编程语言中。。。。。。
代码如下
#include<stdio.h>
#include<math.h>
#define pi 3.1415926
int main()
{
    int n,i,m,b;
    double a;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        a=0;
        scanf("%d",&m);
        a=(m*log(m)-m+0.5*log(2*pi*m))/log(10.0);//注意 这条语句        b=(int)a+1;
        printf("%d\n",b);
    }
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics