PKU 1423 Big Number

Big Number
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7691 Accepted: 2412

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 <= m <= 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

2
10
20

Sample Output

7
19

Source

Dhaka 2002
题目大意:求N!的位数。
分析:题目对时间卡的太紧,主要要在时间方面做文章。写了好多次都超时,学了别人的代码。

组合计数的渐进值问题是组合论的一个研究方向。 Stirling公式给出一个求n!的近似公式:n! ~ ,它对从事计算和理论分析都是有意义的。公式的推导请参考:http://www.cs.cityu.edu.hk/~luoyan/mirror/tsinghua/combinemaths/1/1_3.htm

假设10^x=n!,则x=log10(n!)~log10(2n)+nlog10(n/e),那么对x取下整即可求得结果;注意,以上公式对n>3成立,当n<=3时,x=1

4041724 lin_miao0818 1423 Accepted 228K 0MS C 437B 2008-09-08 22:03:12
提交代码:
#include <stdio.h>
#include <math.h>
void main()
{
       int m,n;
       double r;
       double pi=3.14159265359;
       double e=2.718281828459;
       scanf("%d",&n);
       while(n--)
       {
              scanf("%d",&m);
              r=0.0;
              if(m>3)
              {
                    r=log10(2*pi*m)/2+m*log10(m/e);
              }
              m=r+1;
              printf("%d/n",m);
       }
}

你可能感兴趣的:(Integer,input,each,encryption,output,Numbers)