Topic Source Description
In many applications very large integers numbers is required. Some of these applications is using keys for secure transmission of data, encryption, etc. In this problem you is given a number, you has to determine the number of digits in the factorial of the number.
In many applications, you need to use very large integers. Some of these applications are using keys for secure data transfer, encryption, and so on. In this problem, you get a number, you have to determine the number of digits of the factorial of Input
The input consists of several lines of integers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer per line, 1 <= m <= 10^7 Output
The output contains the number of digits of the factorial of the integer that appears in the input. Sample Input
2
20
Sample Output
7
19
Source
Dhaka 2002 Analyze
The test is Stirling formula ...
z = x ^ y = = y = LOGX Z
We know the number of bits of n is (LG N) + 1
When n is very large, n! Close to sqrt (2 * PI * N (n/e) ^n).
Take the logarithm on both sides:
LG n! = (LG 2PIn)/2 + n * LG N/E
So:
N! The number of bits is: res = (LG 2PIn)/2 + N * LG n/e + 1; Code
#include <iostream> #include <cmath> using namespace std;
Const double e = 2.7182818284590452354, pi = 3.141592653589793239; Double Strling_digits_num (int n) {return log10 (2*pi*n)/2.0+n* (log10 (n/e)); 0ms//return log10 (sqrt (2 * pi * n)) + N * log10 (n/e);
16MS} int main () {int t;
cin>>t;
while (t--) {int n;
cin>>n;
Double m=0;
M=strling_digits_num (n);
int answer= (int) m; Attention....
10 of the N-th side has n+1 digit answer++;
cout<<answer<<endl;
} system ("Pause");
return 0; }