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 contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.
input
The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.
Output
Print integer s — the value of the required sum modulo 109 + 7.
Sample Input
3 4
Sample Output
4
Hint
题意
给你n,m,让你输出n%1+n%2+n%3+....+n%m
答案需要mod1e9+7
题解:
n%i = n - i * [n/i]
所以 sigma(n%i) = n * m - sigma(i * n/i)
在一段区间内,n/i都是不会变化的,所以利用这一点,我们就可以暴力sqrt去处理就好了
但是有一些区间我们最后并没有处理到,怎么办?
直接再暴力一发去处理就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
long long n,m;
scanf("%lld%lld",&n,&m);
long long ans = (n%mod)*(m%mod)%mod;
long long S = sqrt(n+5);
long long k = m+1;
for(int i=1;i<=min(n,S);i++)
{
long long r = n / i;
long long l = n / (i+1)+1;
r = min(r,m);
if(l>r)continue;
k = min(k,l);
long long s1 = (l+r);
long long s2 = (r-l+1);
if(s1%2==0)
s1/=2LL;
else
s2/=2LL;
long long K = (s1%mod)*(s2%mod)%mod;
K = (i * K)%mod;
ans-=K;
ans%=mod;
if(ans<0)ans+=mod;
}
for(int i=1;i<k;i++)
{
ans-=(n-n%i);
ans%=mod;
if(ans<mod)ans+=mod;
}
cout<<ans%mod<<endl;
}
Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学的更多相关文章
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...
- 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 + ... ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA链上最大值
E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Descrip ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- 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 ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
随机推荐
- Android实例] android获取web服务器端session并验证登陆
传统网页实现用户登陆一般采用session或cookie记录用户基本信息又或者两者结合起来使用.android也可以采用session实现用户登陆验证并记录用户登陆状态时的基本信息,session是在 ...
- 部署测试环境(ubuntu+mysql+tomcat)
背景:入职新公司,广州这边没有测试开发环境,需要自己搭建一个:要求ubuntu+mysql+tomcat有具体版本要求: 2015/4/13 下载Ubuntu12.04 http://mirror ...
- 高手就用Chrome不安全模式
背景:最近玩CSS3和HTML玩得不可开交. 既然要用浏览器的话,就最好在浏览器中设置一个主页,以前徒简洁就一直用百度的搜索页做主页,但是现在百度邪恶的各种广告实在让我恶心,而且一些文献资料中国网站上 ...
- Linux 下部署单机 hadoop 测试
最终运行结果展示: 格式化namenode. 开始测试 显示测试进程 浏览器查看效果展示:(虽然还不清楚是什么意思,但是能看到这个效果已经很开心了) 话不多说,进入主题: 1. 安装 VMwareSt ...
- 使用Python拼接多张图片
写机器学习相关博文,经常会碰到很多公式,而Latex正式编辑公式的利器.目前国内常用的博客系统,好像只有博客园支持,所以当初选择落户博客园.我现在基本都是用Latex写博文,然后要发表到博客园上与大家 ...
- 数往知来 三层架构 <十四>
三层架构_1 一.三层 就是把程序的各个部分都分离,尽量的底耦合,做到分工明确.责任明确 第一层:Dal 数据访问层 第二层 :Bll 业务逻辑判断层 第三层: UI 界面显示层 比如说数据 ...
- Yii 1 数据库操作 笔记
$result = array( 'id'=>null, 'val'=>0 ); $row1 = Yii::app()->db->createCommand()->ins ...
- erlang常用命令
1 erlang启动时就运行odbc erl -s odbc 2 ping 节点 net_adm:ping('rabbit@COMPUTERNAME'). 3 运行cmd命令 os:cmd(" ...
- HDU ACM 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Cocos2d-JS v3.0 alpha不支持cocos2d-x的Physics integration
cocos2d-x 3.0新的Physics integration,把chipmunk和Box2D封装到引擎内部 auto scene = Scene::createWithPhysics(); s ...