Big Number poj-1423
题目大意:给出一个自然数n,求n!的位数。
注释:n<=$10^7$。
想法:我们显然知道了,直接暴力显然会T掉,而且需要高精度的存在。所以,在此,我们介绍一种公式——Stirling公式。
Stirling公式:$n!\approx\sqrt{2\pi n}(\frac{n}{e})^n$。
令

则



所以
即
,即单调递减,又由积分放缩法有



即
,即


设


利用Wallis公式,


所以


即
粘自度娘

最后,附上丑陋的代码... ...
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 const double e=2.7182818284590452354; 6 const double pi=3.141592653589793239; 7 inline double strling(int n) 8 { 9 return log10(2*pi*n)/2.0+n*(log10(n/e)); 10 } 11 int main() 12 { 13 int cases; 14 int n; 15 double m; 16 int answer; 17 scanf("%d",&cases); 18 while(cases--) 19 { 20 scanf("%d",&n); 21 m=0; 22 m=strling(n); 23 answer=(int)m; 24 answer++; 25 printf("%d\n",answer); 26 } 27 return 0; 28 }
小结:这种结论题就靠题量去强化吧... ...