Harmonic Number

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<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
const int N=1e4+5;
const int MOD=1000;
const double C=0.57721566490153286060651209;
using namespace std;
double res[N];
int main(){
int T,num=1;
int n;
double ans;
res[1]=1;
for(int i=2;i<=10000;i++){
res[i]=res[i-1]+1.0/i;
}
scanf("%d",&T);
while(T--){
scanf("%d",&n);
if(n<=10000){
printf("Case %d: %.10lf\n",num++,res[n]);
}
else{
ans=log(n)+1.0/(2*n)+C;
printf("Case %d: %.10lf\n",num++,ans);
} }
return 0;
}

Harmonic Number (调和级数+欧拉常数)题解的更多相关文章

  1. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  2. C - Harmonic Number(调和级数+欧拉常数)

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

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

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

  4. Harmonic Number(调和级数+欧拉常数)

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

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

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

  6. Harmonic Number 求Hn; Hn = 1 + 1/2 + 1/3 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8; 打表或者调和级数

    /** 题目:Harmonic Number 链接:https://vjudge.net/contest/154246#problem/I 题意:求Hn: Hn = 1 + 1/2 + 1/3 + . ...

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

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

  8. LightOJ 1234 Harmonic Number (打表)

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

  9. 1245 - Harmonic Number (II)(规律题)

    1245 - Harmonic Number (II)   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...

随机推荐

  1. 【Python接口测试】简单系统登录接口测试实例

    我们可以用Jmeter做接口测试,但是呢个人觉得那个有点局限性,用python就灵活很多, 可以按自己的思路来构建比较灵活,下面给大家介绍一个简单的接口测试实例. 一.我们的思路如下: 首先我们要弄清 ...

  2. Git简单入门教程

    1.下载Git,360的软件管家里搜 2.安装Git,下载好之后安装到指定路径下 安装方法有多个复选框的把第一个也选上,其他默认直接next,最后一步什么都不选 3.配置用户信息:(右键-->g ...

  3. Tesseract-OCR 训练过程 V3.02

    软件: jTessBoxEditor Version 0.9 (30 April 2013) Tesseract-OCR win32 v3.02 with Leptonica   训练步骤:   1. ...

  4. linux命令:文件搜索命令

    ---恢复内容开始--- 文件搜索命令:which 命令名称:which 命令所在路径:/usr/bin/which 执行权限:所有用户 语法:which  [命令名称] 功能描述:显示系统命令所在目 ...

  5. Javascript-逻辑或(||)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. promise-async-await

    通常而言,这3个关键字 都是用来「优雅」的处理ajax异步请求的 //es6的时候promise诞生,很好的解决了嵌套回调地狱,改良方案为链式回调. // es2017的时候诞生了async.awai ...

  7. Bootstrap3-文字样式

    Bootstrap将全局font-size设置为14px,line-height为1.428.这些属性直接赋给<body>和所有段落元素.另外,<p>(段落)还被设置了等于1/ ...

  8. Intermediate Python for Data Science learning 3 - Customization

    Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...

  9. Hive 中Join的专题---Join详解

    1.什么是等值连接? 2.hive转换多表join时,如果每个表在join字句中,使用的都是同一个列,该如何处理? 3.LEFT,RIGHT,FULL OUTER连接的作用是什么? 4.LEFT或RI ...

  10. 安装vscode with springboot

    1.安装jdk8 2.下载vscode,一切按照默认配置完成安装.下载地址:https://code.visualstudio.com 3.安装完成后,运行vscode.如果没有任何反应,在命令行上运 ...