【调和级数求和公式】【欧拉常数】I - Harmonic Number

题意:

   求1+1/2+1/3+…+1/n


欧拉常数值:C≈0.57721566490153286060651209

求和公式:S(n)=ln(n)+C+1/(2*n)

公式只对n值很大的数有效

( C++ cmath库中log(n)就是ln(n) )

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma GCC optimize(2)
#define debug cout<<"*"< pii;
typedef pair pll;
typedef pair psi;
typedef pair pcc;
const ll mod=14937;
const ll INF=0x3f3f3f3f3f;
const int maxn=1e6+17;
const int base=233;
const double PI=acos(-1);
const double euler_cons=0.57721566490153286060651209;
const int N=4;

double ans[maxn];
void pre()
{
    ans[1]=1.0;
    for(int i=2;i<=maxn;++i)
    {
        ans[i]=ans[i-1]+1.0/(double)i;
    }
}
int main()
{
    pre();
    int t;
    in(t);
    int cas=0;
    while(t--)
    {
        int n;
        in(n);
        printf("Case %d: ",++cas);
        if(n

 

 

你可能感兴趣的:(数论)