Codeforces 616 E Sum of Remainders
Discription
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).
The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.
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.
Example
3 4
4
4 4
1
1 1
0 数论分块大水题,我是把n%i 转化成 n-i*[n/i]做的233
#include<bits/stdc++.h>
#define ll long long
const int ha=1000000007;
using namespace std;
ll N,M,ans; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline int ci(ll x){
x%=ha;
return x*(ll)(x+1)/2%ha;
} inline void solve(){
ans=M%ha*(N%ha)%ha,M=min(M,N);
for(ll i=1,j,now;i<=M;i=j+1){
now=N/i,j=min(N/now,M);
ans=add(ans,ha-add(ci(j),ha-ci(i-1))*now%ha);
}
printf("%I64d\n",ans);
} int main(){
scanf("%I64d%I64d",&N,&M);
solve();
return 0;
}
Codeforces 616 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 ...
- codeforces 616E Sum of Remainders (数论,找规律)
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 616E - Sum of Remainders
616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...
- Sum of Remainders(数学题)
F - Sum of Remainders Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- codeforces 963A Alternating Sum
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...
- codeforces 616E. Sum of Remainders 数学
题目链接 给两个数n, m. 求n%1+n%2+.......+n%m的值. 首先, n%i = n-n/i*i, 那么原式转化为n*m-sigma(i:1 to m)(n/i*i). 然后我们可以发 ...
随机推荐
- servlet上传多个文件(乱码解决)
首先,建议将编码设置为GB2312,并在WEB-INF\lib里导入:commons-fileupload-1.3.jar和commons-io-2.4.jar, 可百度下下载,然后你编码完成后,上传 ...
- AOP日志组件 多次获取post参数
AOP日志组件 多次获取post参数 需求:新增接口日志组件.通过拦截器对接口URL进行拦截处理,然后将接口post请求的参数与结果,写入日志表. 问题:POST方法的参数是存储在request.ge ...
- java常用流处理工具StreamTool 常见的InputStream流转字符串, 转字节数组等等
ava 常用流处理工具 StreamTool ,常见的InputStream 流转字符串, 转字节数组等等 **应用场景: ** 1. 文件上传 2. js / css / img 等文件读取输出. ...
- javaEE(6)_JSP
一.什么是JSP 1.JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术,只用JSP就可以开发动态web资源. 2.为什么J ...
- Greenplum介绍-table
GP中的table和其它关系型数据表是一样的,除了数据被分布在不同的segment以外. 建表时需定义以下几个方面:1. 指定列和数据类型2. 约束3. 分布策略4. 数据存储方式5. 大表分区策略 ...
- perl学习之:字符串函数
一.打开.关闭文件 open的返回值用来确定打开文件的操作是否成功,当其成功时返回非零值,失败时返回零,因此可以如下判断: if (open(MYFILE, "myfile" ...
- 流程控制主while,for,python画金字塔,画9*9乘法表
5.6 自我总结 一.流程控制while 1.while while True: #while + 条件满足进行下面的循环 age = input('age:') #while 循环的内容 2.whi ...
- int main(int argc,char *argv[])的具体含义
int main(int argc,char * argv[]) argv为指针的指针 argc为整数 char **argv or: char *argv[] or: char argv[][] m ...
- eclipse代码格式化快捷键无法使用
[产生原因] Ctrl+Shift+F快捷键组合被其他应用占有,如输入法. [解决方案] 关闭或更换其他应用快捷键或更换eclipse对应的快捷键组合.
- 2019年最新 Python 模拟登录知乎 支持验证码
知乎的登录页面已经改版多次,加强了身份验证,网络上大部分模拟登录均已失效,所以我重写了一份完整的,并实现了提交验证码 (包括中文验证码),本文我对分析过程和代码进行步骤分解,完整的代码请见末尾 Git ...