http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1234 Description In mathematics, the nth harmonic number is the sum of th…
Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1234 Description In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In this p…
D - Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1234 Description In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In th…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 Sample Input Sample Output Case : Case : 1.5 Case : 1.8333333333 Case : 2.0833333333 Case : 2.2833333333 Case : 2.450 Case : 2.5928571429 Case : 2.7178571429 Case : 2.8289682540 Case : 18.89…
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 c…
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1245 Description I was trying to solve problem '1234 - Harmonic…
链接: https://vjudge.net/problem/LightOJ-1245 题意: I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) res = res + n / i; return res; } Yes, my error…
题意: 求调和级数,但n很大啦.. 解析: 分段打表  每间隔50存储一个数,在计算时  只需要找到离输入的n最近的那个数 以它为起点 开始计算即可 emm...补充一下调和级数的运算公式   r为常数,r=0.57721566490153286060651209(r就是欧拉常数). 看一下这位的博客:https://www.cnblogs.com/weiyuan/p/5737273.html #include <iostream> #include <cstdio> #inclu…
题目给的时间限制是3s,所以可以直接暴力来做,注意n的取值范围是1e8,如果开一个1e8的数组会RE.分段打表,可以每100个数记录一次,然后对每次询问先找到它所在的区间,然后在暴力往后找.(学到了~~) #include<bits/stdc++.h> using namespace std; ; double mp[N]; void inint(){ ; ;i<=;i++){ ans+=(double)1.0/i; ==) mp[i/]=ans; } } int main(){ ini…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 给你一个数n,让你求 这个要是直接算的话肯定TLE,要是用1e8的数组预处理存储答案也一定MLE. 所以我用1e6的数组存储每100个数的答案,然后每次给你n的时候顶多算99次. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题, i     1  2   3   4   5   6   7    8 a    8  4   2   2   1   1   1    1 你可以多写几组你会发现 有8-4个1:4-2个2:...其他例子也是这样: 当n = 10时 n/1 = 10, n/2 = 5说明(5, 10]这个前开后闭的区间…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:求f(n)=n/1+n/2.....n/n,其中n/i保留整数 显然一眼看不出什么规律.而且n有2e31直接暴力肯定要出事情 但是f=n/x这个函数很好关于y = x 对称对称点刚好是sqrt(n) 于是就简单了直接求sum+n/i (i*i<n && i >=1) 然后乘以2,再减去i*i即可. 这个i*i表示的是什么呢,由于对称上半部份的值完…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. 题解:显然直接longlong存不下.暴力肯定不行啦.这题真的写了很久,死都不懂怎么找的公式啊.然后在wjd的帮助下懂了这题. 我们先列举几个例子 有没有发现他们的共同点,就是除到一定程度,就会变成1.这个临界点是sqrt(n).那在sqrt(n)前面我们要算的就是这个数对于1,2,3……sqrt(…
分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring…
题目大意:对下列代码进行优化 long long H( int n ) {    long long res = 0;    for( int i = 1; i <= n; i++ )        res = res + n / i;    return res;} 题目思路:为了避免超时,要想办法进行优化 以9为例: 9/1 = 9 9/2 = 4 9/3 = 3 9/4 = 2 9/5 = 1 9/6 = 1 9/7 = 1 9/8 = 1 9/9 = 1 拿1来看,同为1的区间长度为:9…
题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In…
1245 - Harmonic Number (II)   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int n ) {     long long res = 0;     for( int i =…
题目链接:https://vjudge.net/problem/LightOJ-1245 1245 - Harmonic Number (II)    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int…
Harmonic Number (II)   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int n ) {    long long res = 0;    for( int i = 1; i <= …
I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int n ) {    long long res = 0;    for( int i = 1; i <= n; i++ )        res = res + n / i;    return res;} Yes, my error was that I was using the integer…
题解:隔一段数字存一个答案,在查询时,只要找到距离n最近而且小于n的存答案值,再把剩余的暴力跑一遍就可以. #include <bits/stdc++.h> using namespace std; const int N = 1e8 + 10; const int M = 2e6 + 10; double a[M]; void Init() { a[0] = 0.0; double ans = 1; for( int i = 2; i < N; i ++) { ans += 1.0 /…
原题链接http://acm.hust.edu.cn/vjudge/contest/121397#problem/A 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 wit…
/** 题目: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: 知识点: 调和…
/* LightOJ1234 Harmonic Number http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1234 打表 分块 由于只有加法运算,1e8时间是可以承受的. 然而空间无法承受,于是以50个单位为一块进行分块. */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmat…
题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式,但欧拉给出过一个近似公式:(n很大时)       f(n)≈ln(n)+C+1/2*n       欧拉常数值:C≈0.57721566490153286060651209       c++ math库中,log即为ln. 题解: 公式:f(n)=ln(n)+C+1/(2*n); n很小时直接求…
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…
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…
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. InputInput starts with an integer T (≤ 10000), denoting the number of test cases. Each case s…
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 c…
/** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数的和.n达到2^31 - 1; 思路: 首先我们观察一下数据范围,2^31次方有点大,暴力会超时,所以我们看看有没有啥规律,假设 tmp 是 n/i 的值,当n == 10的时候(取具体值) 当 tmp = 1 时,个数 是10/1 - 10/2 == 5个 当 tmp = 2 时,个数 是10/2…