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. 使用Firebug和FirePHP调试PHP

    大家都知道Firebug,可能不知大FirePHP,它也是FireFox插件用来调试PHP的,首先确保你安装了Firebug,然后再去安装FirePHP,这是你会看到Firebug多了一只蓝色的虫: ...

  2. IoC(控制反转)

    在传统的编程中,我们通过内部代码来控制组件之间的关系,但是这种实现方式,容易造成组件之间的高耦合.IoC能够很好地解决这个问题,它将组件间的关系从程序内部上提到外部容器来管理.IoC的核心目标是通过简 ...

  3. 谈谈final、finally和finalize

    final: final为修饰符, 如果类被声明为final,则不能派生新子类. 如果变量被声明为final,则必须在声明时初始化,在以后的引用只能读取,不可修改. 如果方法被final声明,则只能使 ...

  4. Java Core 学习笔记——3.char/Unicode/代码点/代码单元

    通用字符集(UCS) UCS是由ISO制定的ISO 10646(或称ISO/IEC 10646)标准所制定的标准字符集. UCS包括了其他所有的字符集(包含了已知语言的所以字符). ISO/IEC 1 ...

  5. SpringMVC + Spring + MyBatis 学习笔记:提交数据遭遇基础类型和日期类型报400错误解决方法

    系统:WIN8.1 数据库:Oracle 11GR2 开发工具:MyEclipse 8.6 框架:Spring3.2.9.SpringMVC3.2.9.MyBatis3.2.8 使用SpringMVC ...

  6. 僵尸进程&孤儿进程

    http://www.cnblogs.com/Anker/p/3271773.html

  7. Systemd Unit文件中PrivateTmp字段详解-Jason.Zhi

    如下图,在开发调试的时候会遇到这么一个问题. file_put_contents时,$tmp_file显示的目标文件是/tmp/xxx.而这个文件实际放在linux的目录却是/tmp/systemd- ...

  8. leetcode@ [146] LRU Cache (TreeMap)

    https://leetcode.com/problems/lru-cache/ Design and implement a data structure for Least Recently Us ...

  9. windows下python的包管理器pip安装

    pip:  A tool for installing and managing Python packages. 要用到第三方包,python的版本就必须是2.7 https://pypi.pyth ...

  10. linux 从命令行自动识别文件并将其打开的命令

    若是shell是 zsh,则可: 使用 alias -s 定义后缀别名 (zsh) % alias -s pl=perl % script.pl perl script.pl % alias -s p ...