1245 - Harmonic Number (II)---LightOJ1245
http://lightoj.com/volume_showproblem.php?problem=1245
题目大意:一个数n除以1到n之和
分析:暴力肯定不行,我们可以先求1~sqrt(n)之间的每个数的个数,然后再求n除以1~sqrt(n)之间的数的和
这样算下来就只有2*sqrt(n)的复杂度
最后还要排除多加的,、
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue> using namespace std;
typedef long long int LL;
#define N 10001000
#define ESP 1e-8
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a)) int main()
{
int T, t=;
scanf("%d", &T);
while(T --)
{
LL n;
scanf("%lld", &n); LL sum =;
for(int i=; i<=sqrt(n); i++)
{
sum += n/i;
} for(int i=; i<=sqrt(n); i++)
{
sum += (n/i - n/(i+)) * i;
} if(n/(int)sqrt(n) == (int)sqrt(n))
sum -= (n/sqrt(n) - n/(sqrt(n)+)) * sqrt(n); printf("Case %d: %lld\n", t++, sum);
}
return ;
}
1245 - Harmonic Number (II)---LightOJ1245的更多相关文章
- 1245 - Harmonic Number (II)(规律题)
1245 - Harmonic Number (II) PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- LightOJ - 1245 - Harmonic Number (II)(数学)
链接: https://vjudge.net/problem/LightOJ-1245 题意: I was trying to solve problem '1234 - Harmonic Numbe ...
- 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 题意:求f(n)=n/1+n/2.....n/n,其中n/i保留整数 显 ...
- LightOJ 1245 - Harmonic Number (II)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. ...
- light oj -1245 - Harmonic Number (II)
先举个例子,假如给你的数是100的话,将100/2=50;是不是就是100除100-51之间的数取整为1: 100/3=33;100除50到34之间的数为2,那么这样下去到sqrt(100);就可以求 ...
- 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++ ) ...
随机推荐
- SHA1算法
public string SHA1_Hash(string str_sha1_in) { SHA1 sha1 = new SHA1CryptoServicePro ...
- XidianOJ 1041: Franky的游戏O
题目描述 Franky是super的人造人,来到了n*m的棋盘世界玩冒险游戏. n×m的棋盘由n行每行m个方格组成,左上角的方格坐标是(0,0),右下角的方格坐标是(n-1,m-1). 每次游戏时,他 ...
- adb无法使用,提示error: unknown host service的解决办法
此时,需要辨别电脑的5037端口被哪个应用程序占用的方法:(使用adb时需要5037端口是空闲的) 1. 打开命令行,输入命令:netstat -ano |findstr "5037&quo ...
- jQuery MiniUI Demo
http://www.miniui.com/demo/#src=datagrid/datagrid.html
- c#轻松实现磁性窗口
/// <summary>/// 磁性窗体函数/// </summary>/// <param name="form">窗体控件(一般传this ...
- U-boot中的FDT
1. U-boot为了支持FDT,添加了新的代码:/libfdt目录fdt.h libfdt.h fdt_support.h fdt_support.c 2. http://blog.csdn.net ...
- ubuntu apt 安装
1. ./autogen.sh: libtoolize: not found sudo apt-get install aptitude sudo aptitude install libtool 2 ...
- HttpTool.java(在java tool util工具类中已存在) 暂保留
HttpTool.java 该类为java源生态的http 请求工具,不依赖第三方jar包 ,即插即用. package kingtool; import java.io.BufferedReader ...
- ArcMap 操作笔记
1.SQL查询(in) select * from table where PointID in ('1','2')
- python 传参open
# Author:mologa k = "ab" for i in k: with open('%s.txt'%i,'w') as f: f.write("hello&q ...