日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值

發布時間:2024/4/14 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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


Problem 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 ≤ 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阶乘近似值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。