codeforces 616E Sum of Remainders (数论,找规律)

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+7;
int main()
{
    long long n,m;
    cin>>n>>m;
    long long ans=0;
    ans=(n%mod)*(m%mod)%mod;
    if(m>=n){m=n;}
    long long fx,fy,fz,pre=m;
    long long s=0;
    while(pre>1)
    {
        fy=pre;
        fz=n/pre;
        fx=n/(fz+1);
        long long r;
        if((fy-fx)%2==0)r=((fx+fy+1)%mod)*(((fy-fx)/2)%mod);
        else r=((fx+fy+1)/2)%mod*((fy-fx)%mod);
        s+=(r%mod)*fz%mod;
        s%=mod;
        pre=fx;
    }
    s+=n;
    s%=mod;
    cout<<(ans-s+mod)%mod<<endl;
    return 0;
}

 

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5155818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值