(数论)LightOJ -- 1245
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98634#problem/B(acm14)
Description
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 divisions only. However, you are given n, you have to find H(n) as in my code.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n < 231).
Output
For each case, print the case number and H(n) calculated by the code.
Sample Input
11
1
2
3
4
5
6
7
8
9
10
2147483647
Sample Output
Case 1: 1
Case 2: 3
Case 3: 5
Case 4: 8
Case 5: 10
Case 6: 14
Case 7: 16
Case 8: 20
Case 9: 23
Case 10: 27
Case 11: 46475828386
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <map>
- using namespace std;
- #define N 200005
- int main()
- {
- long long T, iCase=;
- scanf("%d", &T);
- while(T--)
- {
- long long n, i;
- scanf("%lld", &n);
- long long a, num = , sum = n, pre=n;
- for(i=; i<=n; i++)
- {
- a = n/i;
- num += (pre-a);
- sum += (pre-a)*(i-);
- if(num==n)
- break;
- num++;
- sum += a;
- if(num==n)
- break;
- pre = a;
- }
- printf("Case %lld: %lld\n", iCase++, sum);
- }
- return ;
- }
(数论)LightOJ -- 1245的更多相关文章
- LightOJ 1245 数学题,找规律
1.LightOJ 1245 Harmonic Number (II) 数学题 2.总结:看了题解,很严谨,但又确实恶心的题 题意:求n/1+n/2+....+n/n,n<=2^31. ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- lightoj 1245
lightoj 1245 Harmonic Number (II) 题意:给定一个 n ,求 n/1 + n/2 + …… + n/n 的值(这里的 "/" 是计算机的整数除法,向 ...
- 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 1245 Harmonic Number (II)(简单数论)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:求f(n)=n/1+n/2.....n/n,其中n/i保留整数 显 ...
- LightOj 1245 --- Harmonic Number (II)找规律
题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题 ...
- LightOJ 1245 - Harmonic Number (II)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. ...
- LightOJ 1245 Harmonic Number (II) 水题
分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...
- LightOJ - 1245 Harmonic Number (II) 求同值区间的和
题目大意:对下列代码进行优化 long long H( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) ...
随机推荐
- Android Studio 使用入门
Android Studio 快捷键 Action Mac OSX Win/Linux 注释代码(//) Cmd + / Ctrl + / 注释代码(/**/) Cmd + Option + / Ct ...
- spingmvc项目根路径访问不到
问题: 如何改mvc中项目的欢迎页,或者叫做根路径 一个东西快弄完了,就剩下一个问题,应该是个小问题.就是mvc项目的欢迎页,怎么给改下呢 访问根路径http://localhost/demo 怎么都 ...
- Pycharm小知识
1) 重新更改文件名称:(Shift + F6) 2) 设置IDE皮肤主题 File -> Settings -> Appearance -> Theme -> 选择“Al ...
- PAT 1023 组个最小数 (20)(代码+思路)
1023 组个最小数 (20)(20 分) 给定数字0-9各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意0不能做首位).例如:给定两个0,两个1,三个5, ...
- The 10 Best Choices On The Market Review 2018
Looking to buy a scan tool or considering one of Autel Scanner impressive product line?. The company ...
- VS2010插件 VS.PHP 调试开发php程序
VS 插件VS.PHP 调试PHP的方法;不得不说vs强大啊,此断点调试功能在zend都做不到 如图: 设置成功之后,就可以像调试 .Net程序一样试调Php程序了! 调试的步骤: 1.在需要调试的地 ...
- sex在软件开发中的运用--SIX技术
开篇:省略xxx字 keyword:sex . female, male .SIX ,sex integer extention technolgolsl 前言: 对于sex字段的研究,国内,国际尚为 ...
- Netty Reator(三)Reactor 模型
Netty Reator(三)Reactor 模型 Netty 系列目录 (https://www.cnblogs.com/binarylei/p/10117436.html) 本文介绍 DC Sch ...
- Git简单操作命令
Git 1.创建远程分支(git项目已在) git checkout -b cgy git add . git commit -m “add new branch” git push origin c ...
- Longest Turbulent Subarray LT978
A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if: For i <= k < j ...