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). 然后我们可以发 ...
随机推荐
- Hibernate的二级缓存使用(spring使用)
(一)Hibernate的二级缓存策略的一般过程如下: 1) 条件查询的时候,总是发出一条select * from table_name where …. (选择所有字段)这样的SQL语句查询数据库 ...
- UINavgationController
UINavigationBar和UINavigationItem是iOS开发中常用的控件. 1.设置导航栏标题 self.title = @"iOS开发:iOSDevTip"; ...
- redo log日志内容备忘
检查点是一串递增的数字. 在两个检查点之间,存在有一个MLOG_FILE_NAME的文件,里面记录着space和路径和MLOG_CHECKPOINT的一个检查点. MLOG_FILE_NAME总是在上 ...
- (61)zabbix网络发现规则配置实战/详解
开始配置.首先,我们需要定义发现规则,用于扫描.步骤如下 第一步 Configuration >>Discovery>>Create rule,编辑网络发现规则 如上配置,za ...
- Elementary OS上eclipse卡死问题
解决: 1.可以用 sudo ./eclipse -vm /home/username/jdk_path/bin/java 启动但是启动后仍有显示问题. 2. 修改 eclipse.ini 在 -- ...
- LeetCode(2)Add Two Numbers
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...
- centos中python2替换为python3,并解决yum出错
这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...
- Android开发——IntentFilter的匹配规则
1. IntentFilter中的过滤信息 启动Activity分为显式调用和隐式调用,前者没什么好讲的,后者需要Intent能够匹配目标组件的IntentFilter中所设置的过滤信息.包括act ...
- python中判断字符串是否为中文
判断字符串是否在中文编码范围内 for c in s: if not ('\u4e00' <= c <= '\u9fa5'): return False ...
- deine const 等关键字区别
define 属于预编译指令,在程序运行之前就已经编译好:额,定义变量,没有类型信息, const 修饰的变量是不可变的,只是给出了内存地址,且只在程序运行时初始化开辟一块内存空间 const 只修饰 ...