B - 四月纲领 light oj 1245【数论】
来源:互联网 发布:vm12 mac os 编辑:程序博客网 时间:2024/04/28 02:19
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<cstdio>#include<cmath>typedef long long ll;int main(){int t;int n;int cnt=0;scanf("%d",&t);while(t--){ll sum=0;scanf("%d",&n);int i;for(i=1;i<=(int)sqrt(n);i++){sum+=n/i;if(n/i>n/(i+1))sum+=(ll)((n/i-n/(i+1))*i);}i--;if(n/i==i)sum-=i;printf("Case %d: %lld\n",++cnt,sum);}return 0;}
- B - 四月纲领 light oj 1245【数论】
- Light oj 1245 Harmonic Number (II)(基础数论)
- light oj 【数论】1297 - Largest Box【三分】
- Light OJ-----1336数论-----整数拆分推论
- light oj 1245 1245
- Light oj 1245 【数学题】
- Light Oj-1245
- [Light oj] 1245
- B - Discovering Gold Light oj 1030
- Light OJ 1014 Ifter Party [因子分解]【数论】
- LIGHT OJ 1278 Sum of Consecutive Integers [因子个数]【数论】
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1282(B)——Leading and Trailing
- Light oj 1245 - Harmonic Number (II)
- [Light oj] 1245 - Harmonic Number (II)
- 剑指offer之65 滑动窗口的最大值问题
- Andrid的网络开发技术
- 3.0MongoDB对一个collection的常用操作
- leetcode-Remove Linked List Elements
- 汉字转拼音
- B - 四月纲领 light oj 1245【数论】
- 基于Smack3.0.4+ Openfire3.10.2下学习开发IM(四)用户分组操作:添加和删除分组、好友添加指定分组和不指定分组(Roster、RosterGroup和RosterEntry)
- 每天学一点(一)
- 插件问题
- hdoj 3766 Knight's Trip 【】
- c++rand()与srand()的使用
- 小游戏
- LeetCode题解——Unique Binary Search Trees II
- manifest竟然不报错