题目链接:传送门
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37717 Accepted Submission(s): 18160
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 ≤ 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
题目大意:求某数阶乘的位数
解题思路:
1.x的位数 = (int)log10(x)+1
2.斯特灵公式:n! = sqrt(2*Pi*n)*(n/e)^n
Pi = acos(-1.0)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int N = 308;
const int M = 20;
const int INF = 0x3fffffff;
const double Pi = acos(-1.0);
int digits( int n )
{
return (int)(0.5*log10(2*Pi*n)+n*(log10(n)-1.0/log(10)))+1;
}
int main()
{
int n,m;
scanf("%d",&n);
while( n-- ){
scanf("%d",&m);
printf("%d\n",digits(m));
}
return 0;
}