(数论)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++ ) ...
随机推荐
- java学习笔记1--基础知识
1.java数据类型 2.类之间的几种关系
- 796B Find The Bone
B. Find The Bone time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Thrift.1
1. 依据thrift生成相对应语言的代码 [Ref]: http://wiki.apache.org/thrift/ThriftGeneration [Todo] 2. 如何使用生成的代码 [Ref ...
- eclipse自动添加javadoc注释
参考文档: https://jingyan.baidu.com/article/36d6ed1f70ea9c1bce488350.html https://www.cnblogs.com/yangji ...
- Ajax原生四大步骤
1.首先创建一个js文件夹名为common.js.创建一个createXhr()的函数.在此方法中创建异步对象XMLHttpRequest,后面使用的时候直接引入common.js文件,然后进行调用就 ...
- .Net直接将Web页面table导出到Excel
项目管理系统有个统计表需要导出到Excel表中.常用的方法是在后台C#代码查询数据再写入Excel表中最后保存在目标路径. 为减轻数据库服务器的压力和保持页面的样式,能否直接将页面的表格直接导出到Ex ...
- PDO beginTransaction (),exec(),commit ()
$dsn = 'sqlsrv:server=.\SQLExpress;Database=thinkphp'; $user = 'admin'; $password = 'pass1234'; try ...
- python console 设立快捷键 学习源码 用到英语
arbitrary---随意 iterable----迭代 invalid syntax -----无效的语法 subscriptable ----可索引访问的
- 异常处理(异常解析器) 和 对于Properties类型的属性的配置
在程序运行中,有可能因为用户的不当操作,发生异常.. 在springmvc中可以根据不同的异常配置不同的处理方式 1.例如出现 这个类型异常 org.springframework.web.multi ...
- 绩效沟通-BEST原则
BEST原则指在进行绩效/IDP面谈的时候按照以下步骤进行: 案例:小赵经常在制作标书时候犯错误 Behavior description 描述行为 小赵,8月6日,你制作的标书,报价又出现了错误,单 ...