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的更多相关文章

  1. LightOJ 1245 数学题,找规律

    1.LightOJ 1245   Harmonic Number (II)   数学题 2.总结:看了题解,很严谨,但又确实恶心的题 题意:求n/1+n/2+....+n/n,n<=2^31. ...

  2. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  3. lightoj 1245

    lightoj 1245 Harmonic Number (II) 题意:给定一个 n ,求 n/1 + n/2 + …… + n/n 的值(这里的 "/" 是计算机的整数除法,向 ...

  4. LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)

    Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...

  5. lightoj 1245 Harmonic Number (II)(简单数论)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:求f(n)=n/1+n/2.....n/n,其中n/i保留整数 显 ...

  6. LightOj 1245 --- Harmonic Number (II)找规律

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题 ...

  7. LightOJ 1245 - Harmonic Number (II)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. ...

  8. LightOJ 1245 Harmonic Number (II) 水题

    分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...

  9. LightOJ - 1245 Harmonic Number (II) 求同值区间的和

    题目大意:对下列代码进行优化 long long H( int n ) {    long long res = 0;    for( int i = 1; i <= n; i++ )      ...

随机推荐

  1. javascript 重构alert()

    javascript问题,关于重构window.alert()后,然后调用window原本的window.alert()的方法 大神们,问个问题,如果在script标签的第一行散写,重构了window ...

  2. ubuntu16.04安装wps

    下载: 我的电脑是64位的,所以选择64bit的deb包进行下载 1.下载地址:http://community.wps.cn/download/(去WPS官网下载) 安装: 2.执行安装命令:sud ...

  3. C++11并发编程实战 免费书籍

    C++11 博客http://www.cnblogs.com/haippy/p/3284540.html 网上推荐的C++多线程基本都是C++ Concurrency in Action 英文版的,中 ...

  4. andorid 网格视图GridView

    .xml <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android=&qu ...

  5. phpstorm+xdebug调试代码

    1工具 #phpstorm 前面有文章介绍如何安装 #phpStudy 官网下的2018最新的安装包,php环境使用的也是最新的php7.0nts 2开启php Xdebug拓展 开启拓展,phpSt ...

  6. iOS.-.cxx_destruct

    -.cxx_destruct 方法: 该方法是由编译器生成的方法. 1. “ARC actually creates a -.cxx_destruct method to handle freeing ...

  7. POJ1966 Cable TV Network

    原题链接 割去点使得无向图不连通,和最小割相似. 我们可以将点转化成边,这样就能跑最小割了. 枚举每两个不能直接到达的点\(S,T\),使得删去一些点(除去这两个点)使得这两个点不连通(若两点能直接到 ...

  8. CH6901 骑士放置

    原题链接 和棋盘覆盖(题解)差不多.. 同样对格子染色,显然日字的对角格子是不同色,直接在对应节点连边,然后就是二分图最大独立集问题. #include<cstdio> #include& ...

  9. Python数据库工具类MySQLdb使用

    MySQLdb模块用于连接mysql数据库. 基本操作 # -*- coding: utf-8 -*-       #mysqldb       import time, MySQLdb       ...

  10. Netty Reator(二)Scalable IO in Java

    Netty Reator(二)Scalable IO in Java Netty 系列目录 (https://www.cnblogs.com/binarylei/p/10117436.html) Do ...