链接
题意:多次询问求Hn
解法:当n>1e6时 使用求和公式: C≈0.57721566490153286060651209
当n<=1e6 时,预处理求。
#include<bits/stdc++.h> using namespace std; int t; int n; double mp[1000004]; int main() { double hh=0; for(int i=1;i<=1000000;i++) { hh+=(double)(1.0/i); mp[i]=hh; } scanf("%d",&t); int tt=1; while(t--) { int h; scanf("%d",&h); double ans=log(h)+0.57721566490153286060651209+1.0/(2*h); if(h<=1000000) ans=mp[h]; printf("Case %d: %.10lf\n",tt++,ans) ; } }
Harmonic Number 调和级数求和
最新推荐文章于 2024-03-18 22:01:52 发布