Big Number poj-1423
题目大意:给出一个自然数n,求n!的位数。
注释:n<=$10^7$。
想法:我们显然知道了,直接暴力显然会T掉,而且需要高精度的存在。所以,在此,我们介绍一种公式——Stirling公式。
Stirling公式:$n!\approx\sqrt{2\pi n}(\frac{n}{e})^n$。
令
![技术分享图片](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D95/sign=e50de77ea1ec08fa22001fa258ee9ab1/d4628535e5dde71182e10037a6efce1b9d16613b.jpg)
则
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D141/sign=4881d47a86d6277fed12363c19391f63/7acb0a46f21fbe09a4e383d56a600c338644adb6.jpg)
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D86/sign=732c3d0afaedab64707240c6f636564b/eaf81a4c510fd9f9000916a8242dd42a2934a4d1.jpg)
![技术分享图片](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D151/sign=bf10c27e8d5494ee83220b1c1cf7e0e1/3ac79f3df8dcd100f66fbbe0738b4710b8122f7b.jpg)
所以
即
,即单调递减,又由积分放缩法有
![技术分享图片](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D57/sign=524134588326cffc6d2abfb5b801aaa8/d439b6003af33a870c5442dbc75c10385343b532.jpg)
![技术分享图片](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D63/sign=c2a278d543a7d933bba8e770ac4b41b0/7acb0a46f21fbe09a67281d56a600c338644adc7.jpg)
![技术分享图片](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D154/sign=162a1b4c1c30e924cba4983478096e66/f31fbe096b63f6247a423f478444ebf81a4ca352.jpg)
即
,即
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D88/sign=f16b90a35543fbf2c12cab2bb17ec78b/a686c9177f3e6709fe0af0543dc79f3df8dc5516.jpg)
![技术分享图片](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D41/sign=2b9b13d0452309f7e36fac13730eee77/2cf5e0fe9925bc3138b107dc5ddf8db1ca137081.jpg)
设
![技术分享图片](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D87/sign=2803e7a39922720e7fceeffd79cbeb99/3b292df5e0fe99259dc52b9135a85edf8cb17121.jpg)
![技术分享图片](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D132/sign=82a06324ac6eddc422e7b0f80bdab6a2/8b82b9014a90f603ffd9d1863812b31bb151ed82.jpg)
利用Wallis公式,
![技术分享图片](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D143/sign=3e827aca5ab5c9ea66f307e7e638b622/37d12f2eb9389b5045dbac938435e5dde6116ece.jpg)
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D346/sign=aa4a7c183801213fcb3348d862e636f8/dc54564e9258d1099484e173d058ccbf6d814d8f.jpg)
所以
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D64/sign=f701b77164380cd7e21ea1e9a044c121/f9dcd100baa1cd1135f43ae1b812c8fcc2ce2db4.jpg)
![技术分享图片](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D155/sign=4c890e0183025aafd7327aceceecab8d/060828381f30e9242503d4f04d086e061c95f748.jpg)
即
粘自度娘
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D157/sign=d82c97d5b999a9013f355f332a940a58/0b46f21fbe096b63313815910d338744eaf8acca.jpg)
最后,附上丑陋的代码... ...
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 }
小结:这种结论题就靠题量去强化吧... ...