(数论)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++ ) ...
随机推荐
- 9.4-9.19 h5日记总结
总结: 1.标签 (1)单.双标签 (2)块级.行级标签 (3)标签的属性 2.CSS (1)选择器 *.id.class.标签.后代.子代.并集.交集.伪类.结构 (2)层叠性,即选择器权重的计算 ...
- [转]C#中HttpClient使用注意:预热与长连接
最近在测试一个第三方API,准备集成在我们的网站应用中.API的调用使用的是.NET中的HttpClient,由于这个API会在关键业务中用到,对调用API的整体响应速度有严格要求,所以对HttpCl ...
- txt写入时报错出现:正由另一进程使用,原来是多此一举的操作
//if (!File.Exists(newfilepath + "\\" + name + num + ".txt")) //{ // File.Create ...
- Myeclipse2013破解方法
1.先关闭Myeclipse2013 2.(1)输入usercode可以随便输入,(2)然后选择Myeclipse的版本,(3)点击systemid按钮 3.点击Tools菜单栏下的RebuildKe ...
- html标签二
1.没有前后顺序的信息列表<ul> <li></li> <li></li></ul>2.有序列表 <ol> < ...
- 分析params_s方法
/** * 解析启动模式参数 * @param $opt */ static public function params_s($opt) { //判断传入了s参数但是值,则提示错误 if ((iss ...
- 最大子序列(java版)
package com.algorithm.test; /** * 最大子序列 * @author LiFen * */ public class LargestSubsequence { publi ...
- How to update XENTRY Connect C5 software with .iso file
07.2018 Xentry Mercedes SD Connect c5 software update manual for newbies: Important: If you have XDO ...
- 洛谷1993 小K的农场
原题链接 裸的差分约束. \(X_a-X_b\geqslant C\) \(X_a-X_b\leqslant C\Rightarrow X_b-X_a\geqslant -C\) \(X_a-X_b\ ...
- Linux命令大全完整版
1. linux系统管理命令 adduser 功能说明:新增用户帐号.语 法:adduser补充说明:在Slackware中,adduser指令是个script程序,利用交谈的方式取得输入的用户帐 ...