大数阶乘

来源:互联网 发布:windows无法访问xp 编辑:程序博客网 时间:2024/05/16 02:19

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26436    Accepted Submission(s): 12031


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
21020
 

Sample Output
719

       //一个超级强大的公式,斯特林公式 n!=(2*pi*n)^1/2 *(n/e)^n;求大数阶乘
                  //求位数的时候想到用log10,一个大数运算就是如此简单了
#include<iostream>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
const double e=exp(1.0);
int main()
{
int n,i,k;
while(cin>>n)
{
for(i=0;i<n;i++)
{
 cin>>k;
 if(k==1) cout<<k<<endl;
 else
cout<<int(0.5*log10(2*PI*k)+k*log10(k/e)+1)<<endl;
}
return 0;
}
}
0 0
原创粉丝点击