Big Number
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40523
Accepted Submission(s): 19800
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
2
10
20
Sample Output
7
19
题意: 给你几个 1e7范围内的数,让你判断这些数的阶乘有多少位???
公式如下:
N!=2πn−−−√(ne)n
N
!
=
2
π
n
(
n
e
)
n
化简如下:
log10(n!)=log10(2πn−−−√(ne)n) l o g 10 ( n ! ) = l o g 10 ( 2 π n ( n e ) n )
原式=(ln(2πn√(ne)n)ln10) 原 式 = ( l n ( 2 π n ( n e ) n ) l n 10 )
原式=0.5∗ln(2πn)+n∗lnn−nln10 原 式 = 0.5 ∗ l n ( 2 π n ) + n ∗ l n n − n l n 10
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<iomanip>
#define ull unsigned long long
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
using namespace std;
int main(){
int T;cin>>T;
while(T--) {
int x;cin>>x;
int res = (int)((0.5*log(2*PI*x) + x*log(x) - x)/log(10));
cout<<res+1<<endl;
}
return 0;
}