Harmonic Number LightOJ - 1234 (分段打表)

题意:

求调和级数,但n很大啦。。

解析:

分段打表  每间隔50存储一个数,在计算时  只需要找到离输入的n最近的那个数 以它为起点 开始计算即可

emm。。。补充一下调和级数的运算公式

  r为常数,r=0.57721566490153286060651209(r就是欧拉常数)。

看一下这位的博客:https://www.cnblogs.com/weiyuan/p/5737273.html

 

 

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 100000000
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
double ch[maxn/50+10];
int main()
{
    int T, cnt = 1;
    double sum = 0;
    ch[0] = 0;
    for(int i=1; i<=maxn; i++)
    {
        sum += 1/(double)i;
        if(i % 50 == 0)
            ch[cnt++] = sum;
    }
    int kase = 0;
    cin>> T;
    while(T--)
    {
        int n;
        cin>> n;
        double m = ch[n/50];
        for(int i=n/50*50+1; i<=n; i++)
            m += 1/(double)i;
        printf("Case %d: %.10f\n",++kase,m);    

    }
    

    return 0;
}

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9189761.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值