zzuli2183: 就是签到题XD(欧拉常数)
生活随笔
收集整理的這篇文章主要介紹了
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
3234Sample 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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动画多个元素过渡 多个组件过渡 以及过渡
- 下一篇: 风口的猪-中国牛市(动态规划)