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 数学的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Educational Codeforces Round 5 E. Sum of Remainders (思维题)

    题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...

  4. 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 + ... ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  8. 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 ...

  9. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

随机推荐

  1. Sciter使用心得

    1. div双击事件  $(div).onMouse = function(evt) {       switch(evt.type) {          case Event.MOUSE_DCLI ...

  2. GC Buffer Busy Waits处理(转载)

    与单实例不同,在RAC环境中,由于多节点的原因,会因为节点间的资源争用产生GC类的等待,而这其中,GC Buffer Busy Waits又是最为常见的,从性能角度上说,RAC是把双刃剑,用的好,能够 ...

  3. 批量还原数据库 SQL Server 2008

    1.如果你够懒,不想一步一步点路径,一步一步选择 2.如果你连单个备份数据库的存储过程都不想多执行,一般每还原一个需要修改数据库名 下面的脚本适合你: /*********************** ...

  4. How To Set Up Port Forwarding in Linux

    Port forwarding usually used when we want our computer act like a router. Our computer receive the p ...

  5. Bluebird-Core API (三)

    Promise.join Promise.join( Promise<any>|any values..., function handler ) – -> Promise For ...

  6. Arduino+RFID RC522 +继电器

    博客园的第一篇博文就献给Arduino了.不知道能不能坚持自己喜欢的并且记录下来. 起码是个好的开始. 想实现一卡通代替钥匙开启电动车. 简单的原理,通过RC522模块读取一卡通的序列号,在程序中进行 ...

  7. CSStickyHeaderFlowLayout collectionView headerView 悬浮

    github:https://github.com/levyleo/CSStickyHeaderFlowLayout iOS 10 使用时会出现崩溃:https://github.com/CSStic ...

  8. T-SQL游标

    游标是面向行的,它会使开发人员变懒,懒得去想用面向集合的查询方式实现某些功能. 在性能上,游标会迟更多的内存,减少可用的并发,占用带宽,锁定资源,当然还有更多的代码量. 用一个比喻来说明为什么游标会占 ...

  9. windows下揪出java程序占用cpu很高的线程 并找到问题代码 死循环线程代码

    我的一个java程序偶尔会出现cpu占用很高的情况 一直不知道什么原因 今天终于抽时间解决了 系统是win2003 jvisualvm 和 jconsole貌似都只能看到总共占用的cpu 看不到每个线 ...

  10. Java反射机制(创建Class对象的三种方式)

    1:了解什么是反射机制? 在通常情况下,如果有一个类,可以通过类创建对象:但是反射就是要求通过一个对象找到一个类的名称:   2:在反射操作中,握住一个核心概念: 一切操作都将使用Object完成,类 ...