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
Sample Output
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]
相关文章推荐
- POJ1423( 数学公式)
- POJ 1423 &&hdu 1018 Big Number【数学】
- POJ 1423 Big Number——数学题
- POJ 1423 Big Number
- poj 1423 Big Number
- POJ 1423 Big Number 阶乘位数+Stirling+JAVA .
- POJ 1423 Big Number
- POJ-2002 Squares,哈希模板+数学公式!
- poj 1423 big number
- POJ 1423 Big Number
- POJ 1423 Big Number
- poj 1423 Big Number
- POJ1423————Big Number
- POJ 1423 Big Number
- POJ1423 - Big Number(Stirling公式)
- Poj 1423 Big Number//数学,阶乘
- POJ 1423 Big Number
- POJ - 1850 Code(组合数学推公式)
- zoj 1526||poj 1423 big number (大数 stirling公式)
- POJ1019 NumberSequence 【数学公式转化题】