LocalMaxima_NOI导刊2009提高(1)(欧拉-马斯刻若尼常数)
先打表,发现\(ans=\sum_{i=1}^n\frac{1}{i}\)
对于小数据可以直接打表
数据很大时,精度相对就比较宽松
调和级数为:\(\sum_{i=1}^{\infty}\frac{1}{i}\)
自然对数就是:\(\ln (x)\)
欧拉-马斯刻若尼常数:\(\gamma=\lim _{n\to \infty}[(\sum_{i=1}^n)-\ln(n)]=\int_1^{\infty}(\frac{1}{\lfloor x\rfloor}-\frac {1}{x})dx\)
近似值约为:\(\gamma\approx 0.577215664901532860606512090082402431042159335\)
于是这道题就解决了
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<vector>
#include<cstdlib>
#include<ctime>
#define QAQ int
#define TAT long long
#define OwO bool
#define ORZ double
#define F(i,j,n) for(QAQ i=j;i<=n;++i)
#define E(i,j,n) for(QAQ i=j;i>=n;--i)
#define MES(i,j) memset(i,j,sizeof(i))
#define MEC(i,j) memcpy(i,j,sizeof(j))
using namespace std;
const ORZ pho=0.577215664901532;
QAQ n;
ORZ ans;
QAQ main(){
scanf("%d",&n);
if(n<=1000000) F(i,1,n) ans+=1.0/(ORZ)i;
else ans=log(n)+pho;
printf("%.8lf\n",ans);
return 0;
}