Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E
题意很简单就不说了。
因为n % x = n - n / x * x
所以答案就等于 n * m - (n/1*1 + n/2*2 ... n/m*m)
在根号n复杂度枚举x,注意一点当m>n时,后面一段加起来就等于0,就不用再枚举了。
中间一段x1 ~ x2 的n/x可能相等,所以相等的一段等差数列求和。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
vector <LL> myset; //存储x
LL mod = 1e9 + ; int main()
{
LL n, m;
scanf("%lld %lld", &n, &m);
LL k = min(m, n);
myset.push_back(k);
for(LL i = ; i*i <= n; ++i) {
myset.push_back(i);
if(i * i != n) {
myset.push_back(n/i);
}
}
sort(myset.begin(), myset.end());
LL ans = (n%mod)*(m%mod)%mod, cnt = ;
for(LL i = ; i < myset.size() && myset[i] <= k; ++i) {
LL temp = myset[i];
if(cnt) {
LL num;
if((temp - cnt) % )
num = ((temp + cnt + ) / % mod) * ((temp - cnt) % mod) % mod;
else
num = ((temp - cnt) / % mod) * ((temp + cnt + ) % mod) % mod;
num = ((n / temp) % mod * num) % mod;
ans = ((ans - num) % mod + mod) % mod;
}
else {
ans = (ans - n) % mod;
}
cnt = temp;
}
printf("%lld\n", (ans + mod) % mod);
return ;
}
Educational Codeforces Round 5 E. Sum of Remainders (思维题)的更多相关文章
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
- Codeforces - Educational Codeforces Round 5 - E. Sum of Remainder
题目链接:http://codeforces.com/contest/616/problem/E 题目大意:给定整数n,m(1≤n,m≤1013), 求(n mod 1 + n mod 2 + ... ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...
- Educational Codeforces Round 4 A. The Text Splitting 水题
A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...
- Codeforces Educational Codeforces Round 3 B. The Best Gift 水题
B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
随机推荐
- hdu4638 group 树状数组
连接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 题意:就给给你n个数(大小在1-n里),然后给你连续的可以构成一个块,再给你N个询问,每个询问一个l ...
- HDU 1728 逃离迷宫【BFS】
题意:给出一个起点,一个终点,规定的转弯次数,问能否在规定的转弯次数内到达终点--- 这一题是学(看)习(题)的(解)@_@ 主要学了两个地方 一个是剪枝,如果搜到的当前点的转弯次数小于该点turn数 ...
- 微信开发小结-PHP
功能点: 1. 网页授权获得微信用户信息 用户在微信客户端中访问第三方网页,公众号可以通过微信网页授权机制,来获取用户基本信息,进而实现业务逻辑. 注意点:Scope为snsapi_base 只能获 ...
- hadoop NameNode 实现分析
在hadoop 整体分析中,说过nameNode主要是实现一个 blockID 到对应 dataNode的对应关系映射. 现在分析一下腰实现这个映射,nameNode还需要哪些模块. 1 为了方便用户 ...
- BZOJ 1202 狡猾的商人
前缀和+带权并查集. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- 用canvas实现图片滤镜效果详解之灰度效果
前面展示了一些canvas实现图片滤镜效果的展示,并且给出了相应的算法,下面来介绍一下具体的实现方法. 前面介绍的特效中灰度效果最简单,就从这里开始介绍吧. 1.获取图像数据 img.src = ’h ...
- I.MX6 uSDHC SD card register
/**************************************************************************** * I.MX6 uSDHC SD card ...
- xunsearch迅搜体验
安装与启动 http://www.xunsearch.com/doc/php/guide/start.installation 编写配置文件 http://www.xunsearch.com/doc/ ...
- 定时任务处理-Quartz
Quartz Scheduler,定时任务 Quartz是一个作业调度系统(a job scheduling system),负责在约定的时间到达时执行(或通知)其他软件控制.是一个Java的定时任务 ...
- 把十进制数(long型)分别以二进制和十六进制形式输出,不能使用printf系列。
编程实现:把十进制数(long型)分别以二进制和十六进制形式输出,不能使用printf系列. 实现了unsigned long型的转换. // 十进制转换为二进制,十进制数的每1bit转换为二进制的1 ...