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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

zzuli2183: 就是签到题XD(欧拉常数)

發(fā)布時(shí)間:2023/12/16 编程问答 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 zzuli2183: 就是签到题XD(欧拉常数) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

傳送門->點(diǎn)我

Description

In mathematics, we suppose that f(1)=1, f(i)-f(i-1)=1/i, (2<=i<=n)

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.Each case starts with a line containing an integer n (2 ≤ n ≤10^7).

Output

For each case, print the case number and the value of f(n). The answer should be rounded to 10 decimal places.

Sample Input

3234

Sample Output

Case 1: 1.5000000000Case 2: 1.8333333333Case 3: 2.0833333333 題意:求f(n)=1/1+1/2+1/3+1/4…1/n,精確小數(shù)點(diǎn)后10位

知識(shí)點(diǎn):

???? 調(diào)和級(jí)數(shù)(即f(n))至今沒有一個(gè)完全正確的公式,但歐拉給出過一個(gè)近似公式:(n很大時(shí))

?? ?? f(n)ln(n)+C+1/2*n????

????? 歐拉常數(shù)值:C≈0.57721566490153286060651209

????? c++ math庫中,log即為ln。

但是n很小是直接求

貼代碼:

 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define inf 0x3f3f3f3f #define maxn 10000011 double r = 0.57721566490153286060651209; double a[10005]; int main() {a[1] = 1;for(int i=2; i<=10000; i++)a[i] = a[i-1] + 1.0/i;int t;scanf("%d",&t);for (int cas=1; cas<=t; cas++){int n;scanf("%d",&n);if(n <= 10000)printf("Case %d: %.10lf\n",cas,a[n]);else{double sum;sum = log(n) + r + 1.0/(2*n);printf("Case %d: %.10lf\n",cas,sum);}} }


總結(jié)

以上是生活随笔為你收集整理的zzuli2183: 就是签到题XD(欧拉常数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。