Big Number
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
题意: 求n的阶乘的结果有多少位数。
题解: Stirling公式,然后对n!求以10为底的对数就行。
c++ AC 代码:
#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;
}
其实之前数学竞赛培训学过这个公式,第一眼看这个公式的名字就感觉挺熟悉的,不过那时候没好好听课,所有学的不牢。。。