【题目】http://acm.hdu.edu.cn/showproblem.php?pid=1018
【报告】
首先,暴力模拟是绝对会TLE的。。然后看了别人的题解,发现有个斯特林公式(Stirling's approximation):
或更精确的
所以,ans=int(log10(n!))+1=int(0.5*log10(2*pi*x)+x*log10(x/e))+1
【程序】
// Task: 1018 Big Number
// Designer: Rsky 2013/08/26
#include
#include
using namespace std;
int main()
{
int n;
for (cin >> n;n--;)
{
int x;
cin >> x;
cout << int(0.5*log10(2*3.1415726*x)+x*log10(x/2.718281828))+1 << endl;
}
return 0;
}