Harmonic Number

Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:

In this problem, you are given n, you have to find Hn.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 108).

Output

For each case, print the case number and the nth harmonic number. Errors less than 10-8 will be ignored.

Sample Input

12

1

2

3

4

5

6

7

8

9

90000000

99999999

100000000

Sample Output

Case 1: 1

Case 2: 1.5

Case 3: 1.8333333333

Case 4: 2.0833333333

Case 5: 2.2833333333

Case 6: 2.450

Case 7: 2.5928571429

Case 8: 2.7178571429

Case 9: 2.8289682540

Case 10: 18.8925358988

Case 11: 18.9978964039

Case 12: 18.9978964139

题意如题。

题解:考察超内存问题,要分组存储,否则会超内存。

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const int maxn=1e8+;
double a[maxn/+]; //注意+5
void get()
{
double sum=1.0;
a[]=;
a[]=1.0;
for(int i=;i<=maxn;i++)
{
sum+=1.0/double(i);
if(i%==)
a[i/]=sum;
}
}
int main()
{
get();
int t,cas=;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int b=n/;
double ans=a[b];
for(int i=b*+;i<=n;i++) //注意是b*1000
ans+=1.0/double(i);
printf("Case %d: %.10lf\n",cas++,ans);
}
return ;
}

LightOJ 1234 Harmonic Number (打表)的更多相关文章

  1. LightOJ 1234 Harmonic Number(打表 + 技巧)

    http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS     Memory ...

  2. LightOJ 1234 Harmonic Number

    D - Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu S ...

  3. LightOJ 1234 Harmonic Number 调和级数部分和

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 Sample Input Sample Output Case : Case : ...

  4. LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)

    Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...

  5. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  6. LightOJ - 1245 - Harmonic Number (II)(数学)

    链接: https://vjudge.net/problem/LightOJ-1245 题意: I was trying to solve problem '1234 - Harmonic Numbe ...

  7. Harmonic Number LightOJ - 1234 (分段打表)

    题意: 求调和级数,但n很大啦.. 解析: 分段打表  每间隔50存储一个数,在计算时  只需要找到离输入的n最近的那个数 以它为起点 开始计算即可 emm...补充一下调和级数的运算公式   r为常 ...

  8. I - Harmonic Number LightOJ - 1234 (分段打表+暴力)

    题目给的时间限制是3s,所以可以直接暴力来做,注意n的取值范围是1e8,如果开一个1e8的数组会RE.分段打表,可以每100个数记录一次,然后对每次询问先找到它所在的区间,然后在暴力往后找.(学到了~ ...

  9. Light oj 1234 - Harmonic Number

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 给你一个数n,让你求 这个要是直接算的话肯定TLE,要是用1e8的数组预处理存储 ...

随机推荐

  1. SpringMVC配置

    博客园 闪存 首页 新随笔 联系 管理 订阅 随笔- 4  文章- 1  评论- 0  搭建springmvc框架的另一种思路 在一个完整的项目里搭建springmvc框架的时候, 通常情况下,初学者 ...

  2. 【poj2187】 Beauty Contest

    http://poj.org/problem?id=2187 (题目链接) 题意 求点集上两点间最长距离 Solution 凸包+旋转卡壳. 旋转卡壳是看起来很难,但是很好意会也很好实现的算法,但是要 ...

  3. [NOIP2008] 提高组 洛谷P1006 传纸条

    题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是 ...

  4. HDU2196computer(树上最远距离 + DP)

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. 更改动软代码生成器模板 验证Model数据合法性

    1.第一个模板 判断字段是否为空 类 IsNullableType.cmt static public partial class CommonType { public static bool Is ...

  6. PHP中应用GD2函数在图像上添加文字

    <?php header("Content-type:text/html;charset=utf-8"); header("Content-type:image/g ...

  7. 把数据保存到数据库附加表 `dede_addonarticle` 时出错,请把相关信息提交给DedeCms官方。Duplicate entry

    把数据保存到数据库附加表 `dede_addonarticle` 时出错,请把相关信息提交给DedeCms官方.Duplicate entry ’3′ for key ‘PRIMARY’ 你的主键是不 ...

  8. Graphtree--zabbix增强功能(一屏展示所有内容)

    Graphtree--zabbix增强功能 Graphtree由OneOaaS开发并开源出来. 功能 集中展示所有分组设备 集中展示一个分组图像 集中展示一个设备图像 展示设备下的Applicatio ...

  9. &#x开头的是什么编码呢。浏览器可以解释它。如&#20013;&#22269;等同与中文"中国"?

    形如—— &#dddd; &#xhhhh; &#name; ——的一串字符是 HTML.XML 等 SGML 类语言的转义序列(escape sequence).它们不是「编码 ...

  10. 把Linux安装到移动硬盘上

    把Linux安装到移动硬盘上 转载于:http://mrkh.me/install-linux-on-a-portable-hard-drive.html 这一篇文章讲一下,怎么把linux安装到移动 ...