
E. Sum of Remainders
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
input
3 4
output
4
input
4 4
output
1
input
1 1
output
0
题意很好理解,最后求和的时候找找规律就能过;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+;
int main()
{
long long n,m;
cin>>n>>m;
long long ans=;
ans=(n%mod)*(m%mod)%mod;
if(m>=n){m=n;}
long long fx,fy,fz,pre=m;
long long s=;
while(pre>)
{
fy=pre;
fz=n/pre;
fx=n/(fz+);
long long r;
if((fy-fx)%==)r=((fx+fy+)%mod)*(((fy-fx)/)%mod);
else r=((fx+fy+)/)%mod*((fy-fx)%mod);
s+=(r%mod)*fz%mod;
s%=mod;
pre=fx;
}
s+=n;
s%=mod;
cout<<(ans-s+mod)%mod<<endl;
return ;
}