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 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8;
思路:由于1e8,所以直接存表不行。
通过每100个存入数组一个变量值。然后每次查询最多100次就可以了。 其他解法转自http://www.cnblogs.com/shentr/p/5296462.html:
知识点: 调和级数(即f(n))至今没有一个完全正确的公式,但欧拉给出过一个近似公式:(n很大时)
f(n)≈ln(n)+C+1.0/(2*n)
欧拉常数值:C≈0.57721566490153286060651209
c++ math库中,log即为ln。 公式:f(n)=ln(n)+C+1.0/(2*n);
n很小时直接求,此时公式不是很准。 */ #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e4+;
const int N = 1e8;
double a[]; void init()
{
double p = ;
for(int i = ; i <= N; i++){
p += 1.0/i;
if(i%==)
a[i/] = p;
}
}
int main()
{
int T, n, cas=;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
init(); cin>>T;
while(T--)
{
scanf("%d",&n);
double p = ;
for(int i = n/*+; i <= n; i++){
p += 1.0/i;
}
printf("Case %d: %.10lf\n",cas++,p+a[n/]);
} return ;
}
/**
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double C=0.57721566490153286060651209;
double a[10004];
void init()
{
for(int i = 1; i <= 10000; i++){
a[i] = a[i-1]+1.0/i;
}
}
int main()
{
int T, n, cas=1;
init();
cin>>T;
while(T--)
{
scanf("%d",&n);
printf("Case %d: ",cas++);
if(n<=10000){
printf("%.10lf\n",a[n]);
}else
printf("%.10lf\n",log(n)+C+1.0/(2*n));
}
return 0;
}
*/
Harmonic Number 求Hn; Hn = 1 + 1/2 + 1/3 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8; 打表或者调和级数的更多相关文章
- G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;
/** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- LightOJ 1234 Harmonic Number
D - Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu S ...
- Harmonic Number(调和级数+欧拉常数)
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers ...
- LightOJ 1234 Harmonic Number(打表 + 技巧)
http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS Memory ...
- LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- LightOJ 1234 Harmonic Number (打表)
Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- Harmonic Number (调和级数+欧拉常数)题解
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- LightOJ1234 Harmonic Number —— 分区打表
题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number PDF (English) Statistics Foru ...
随机推荐
- Mysql 按条件排序查询一条记录 top 1 对应Mysql的LIMIT 关键字
项目中需要每次查询一个表中的最新的一条记录,表结构里面有日期字段.只需要显示一条记录. Mysql帮助文档里面的解释 3.6.2. 拥有某个列的最大值的行 任务:找出最贵物品的编号.销售商和价格. 这 ...
- Telnet协议详解
转:http://www.cnblogs.com/dazhaxie/archive/2012/06/27/2566054.html 1. 概述 Telnet协议是TCP/IP协议族中的一员,是Inte ...
- Layui 使用问题汇总
1. Layui数据表格中checkbox位置不居中 使用方法渲染的方式生成数据表格,添加了checkbox,但发现checkbox位置不居中,如下图所示 解决办法 通过layui官方社区,找到如下代 ...
- mq
同时每个 Broker 与NameServer 集群中的所有节点建立长连接,定时注册 Topic 信息到所有 NameServer 中. Producer 与 NameServer 集群中的其中一个节 ...
- 【java】在分页查询结果中对最后的结果集List进行操作add()或remove()操作,报错:java.lang.UnsupportedOperationException
场景: 在分页查询结果中对最后的结果集List进行操作add()或remove()操作,报错:java.lang.UnsupportedOperationException 错误: java.lang ...
- opengl中VAO,VBO,IBO用法小结(zz) 【转】
http://cowboy.1988.blog.163.com/blog/static/751057982014380251300/ opengl中VAO,VBO,IBO用法小结 这三个玩意全面取代旧 ...
- 数据挖掘算法之关联规则挖掘(二)FPGrowth算法
之前介绍的apriori算法中因为存在许多的缺陷,例如进行大量的全表扫描和计算量巨大的自然连接,所以现在几乎已经不再使用 在mahout的算法库中使用的是PFP算法,该算法是FPGrowth算法的分布 ...
- CentOS 5 全功能WWW服务器搭建全教程 V3.0
http://hx100.blog.51cto.com/44326/339949/ 一.基本系统安装1.下载CentOS 5我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多.大家可 ...
- 【DB2】SQL0501N FETCH 语句或 CLOSE 语句中指定的游标尚未打开,或者游标标量函数引用中的游标变量尚未打开。 SQLSTATE=24501
在DB2中建立存储过程时使用了隐式游标,在调用的时候报错如下: SQL0501N FETCH 语句或 CLOSE 语句中指定的游标尚未打开,或者游标标量函数引用中的游标变量尚未打开. SQLSTA ...
- loadrunner两个函数:取参数长度和时间戳函数
出自中国IT实验室2014-05-23 00:01 1.web_save_param_length 函数 函数原型:int web_save_param_length( const char *Par ...