POJ - 1423 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

有个题目和这个是一样的点击打开链接

但是这个题目m比较大,所以不能再用数组来求了。

这个题目,可以用斯特林公式。

POJ - 1423 Big Number(斯特林公式)_第1张图片

代码:

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		cout << int(log10(2 * acos(-1.0)*n) / 2 + (log10(n) - 1 / log(10))*n + 1 / log(10) / n / 12)+1<<endl;
	}
	return 0;
}


你可能感兴趣的:(斯特林公式)