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

Source

Problem Setter: Jane Alam Jan
/**
题意:如题
做法:因为n为1e8比较大,然后可以进行打表,每100个存储,然后在进行剩余的
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <queue>
const int maxn = 1e8 + ;
using namespace std;
double mmap[maxn/+];
void init()
{
mmap[] = ;
mmap[] = ;
double sum = 1.0;
for(int i=;i<=maxn;i++)
{
sum += 1.0 / (i*1.0);
if(i % == ) mmap[i/] = sum;
}
}
int main()
{
int Case = ;
int T;
scanf("%d",&T);
init();
while(T--)
{
long long n;
scanf("%lld",&n);
int res = n/;
double tot = mmap[res];
for(int i=res*+;i<=n;i++)
{
tot += (1.0)/(i*1.0);
}
printf("Case %d: %.10f\n",Case++,tot);
}
return ;
}

LightOJ - 1234的更多相关文章

  1. LightOJ 1234 Harmonic Number

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

  2. LightOJ 1234 Harmonic Number (打表)

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

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

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

  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. 1 。 LightOJ 1234 打表法(数据太大,把数据缩小100倍)

    原题链接http://acm.hust.edu.cn/vjudge/contest/121397#problem/A Description In mathematics, the nth harmo ...

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

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

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

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

  8. LightOJ - 1234 分块预处理

    求∑1/i,但是范围很大 和bitmap的想法一样,分个块,均摊复杂度就降下来了 //到底排行榜上的0ms是怎么做到的? #include<bits/stdc++.h> using nam ...

  9. Harmonic Number (LightOJ 1234)(调和级数 或者 区块储存答案)

    题解:隔一段数字存一个答案,在查询时,只要找到距离n最近而且小于n的存答案值,再把剩余的暴力跑一遍就可以. #include <bits/stdc++.h> using namespace ...

随机推荐

  1. POJ 2728 Desert King | 01分数规划

    题目: http://poj.org/problem?id=2728 题解: 二分比率,然后每条边边权变成w-mid*dis,用prim跑最小生成树就行 #include<cstdio> ...

  2. HDOJ.2072 单词数(map)

    单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...

  3. ArrayList动态扩容机制

    初始化:有三种方式 1.默认的构造器,将会以默认的大小来初始化内部的数组:public ArrayList(); 2.用一个ICollection对象来构造,并将该集合的元素添加到ArrayList: ...

  4. OpecnCV训练分类器详细整理

    本文主要是对下面网址博客中内容的实例操作: http://blog.csdn.net/byxdaz/article/details/4907211 在上述博客中,详细的讲述了OpenCV训练分类器的做 ...

  5. Beautiful Soup的一些中文资料

    如果你着急用的话,可以看下这个简略版的,非常简单: 转自  人世间http://rsj217.diandian.com/post/2012-11-01/40041235132 当然,强烈推荐你看一下的 ...

  6. jQuery Lightbox效果插件Boxer

    演示:http://www.jq22.com/yanshi1139 下载:链接: https://pan.baidu.com/s/1o8zaV2q 密码: 2ccy Boxer 是一款基于 jQuer ...

  7. Hadoop 介绍

    1.Hadoop简介 Hadoop[hædu:p]实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有高容错性的特点,并且设计用来部署在低 ...

  8. python socket和简单tcp通信实现

    python 服务端和客户端的简单交互 TCP服务端: 1 创建套接字,绑定套接字到本地IP与端口 s = socket.socket(socket.AF_INET,socket.SOCK_STREA ...

  9. CodeBlocks wrong

    codeblocks官网 Q1. 中文乱码 系统是win,用的是codeblocks编辑器,指定的原文件编码是UTF-8 编译后运行,发现中文在控制台里显示全是乱码 A1: 对此有解决办法,通过给g+ ...

  10. python+selenium+js 处理滚动条

    selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 常见场景: 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的. 这时候需要借 ...