PKU 1423 Big Number

Big Number
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 7691Accepted: 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

题目大意:求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(2∏n)+nlog10(n/e),那么对x取下整即可求得结果;注意,以上公式对n>3成立,当n<=3时,x=1

4041724lin_miao08181423Accepted228K0MSC437B2008-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);
       }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值