您的位置:首页 > 其它

POJ 1423 Big Number (数学公式)

2010-01-28 01:46 489 查看
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

//此题必须用公式才能AC,数据规模太大了
//Stirling公式:    n! = ((2*pi*n)^(1/2))*((n/e)^n); 前提是n > 3
//由此可以导出lg(n!) = (lg(2*pi)+lg(n))/2 + n*(lg(n)-lg(e));
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
int test,n;
long long int s;
const long double c1 = 0.798179868358; //lg(2*pi)
const long double c2 = 0.434294481903; //lg(e)
long double c3;
cin >> test;
while(--test+1)
{
cin >> n;
c3 = log10((double)n);
s = 1;
if(n > 3)
{
s = (c3 + c1)/2 + n * (c3 - c2) + 1;
cout << s << endl;
}
else
cout << 1 << endl;
}
return 0;
}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: