zoukankan      html  css  js  c++  java
  • 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;
    }
     
  • 相关阅读:
    codevs 1199 开车旅行 2012年NOIP全国联赛提高组
    poj 3349 Snowflake Snow Snowflakes
    poj 3264 Balanced Lineup
    求二进制数中1的个数
    20个正则表达式,减少千行代码
    推流脚本
    Navicat 管理工具下载地址,破解版
    emoji表情处理研究
    计算机网络学习
    tcp/ip 学习-通过视频学习
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5155818.html
Copyright © 2011-2022 走看看