HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值
生活随笔
收集整理的這篇文章主要介紹了
HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近一堆題目要補,一直咸魚,補了一堆水題都沒必要寫題解。備忘一下這個公式。
?Stirling公式的意義在于:當n足夠大時,n!計算起來十分困難,雖然有很多關于n!的等式,但并不能很好地對階乘結果進行估計,尤其是n很大之后,誤差將會非常大。但利用Stirling公式可以將階乘轉化成冪函數,使得階乘的結果得以更好的估計。而且n越大,估計得越準確。
傳送門:_(:з」∠)_?
再來一個詳細一點的,傳送門:( ・′ω`・ )?
?
Big Number
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40645????Accepted Submission(s): 19863
?
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 ≤ 107?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?
Source Asia 2002, Dhaka (Bengal) 代碼: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const double e=exp(1); 8 const double pi=acos(-1.0); 9 int main(){ 10 int t; 11 scanf("%d",&t); 12 while(t--){ 13 int n; 14 scanf("%d",&n); 15 if(n==1){printf("1\n");continue;} 16 double s=log10(2.0*pi)/2.0+(n+0.5)*log10(n)-n*log10(e); 17 int ans=ceil(s); 18 printf("%d\n",ans); 19 } 20 return 0; 21 }?
?
?
?
轉載于:https://www.cnblogs.com/ZERO-/p/8440970.html
總結
以上是生活随笔為你收集整理的HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端可视化编程:liveReload安装
- 下一篇: POJ 3253 -- Fence Re