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. visual studio各个版本的差异

  2. POJ3233 Matrix Power Series

    Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. ...

  3. JAVA中toString方法的作用

    因为它是Object里面已经有了的方法,而所有类都是继承Object,所以“所有对象都有这个方法”. 它通常只是为了方便输出,比如System.out.println(xx),括号里面的“xx”如果不 ...

  4. Codeforces 650A Watchmen

    传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...

  5. iOS开源项目汇总

    扫描wifi信息: http://code.google.com/p/uwecaugmentedrealityproject/ http://code.google.com/p/iphone-wire ...

  6. php中图片文件的导入,上传与下载

    ---------------------------------------------图片的导入-------------------------------------------------- ...

  7. 添加一个txt文件(例如在桌面),利用后台对文件写入内容

    string str = "今天天气好晴朗,处处好风光."; //需要将字符串转化成字节数组 byte[] buffer = Encoding.Default.GetBytes(s ...

  8. 初学structs2,表单验证简单补充

    一.使用注解方式,跳过验证某个方法 由于在开发中,我们不需在请求每一个action类中的方法时都要走validate方法,那么我们可以在这些不需要验证的方法上加上@SkipValidation注解即可 ...

  9. 在命令行中运行eclipse中创建的java项目

    在命令行中运行eclipse中创建的java项目 博客分类: java相关 javaeclipse命令行  由于项目要求,需要对eclipse中的项目进行打包,似的可以在客户机上不装eclipse的情 ...

  10. android-android各大手机系统打开权限管理页面

    android系统五花八门,当我们去请求用户的权限的时候,总是会弹出是否允许的对话框. 而且用户一旦不小心点了拒绝,下次就不再询问了,而很多小白用户也不知道怎么去设置.这就导致了很不好的用户体验. 经 ...