1 条题解

  • 1
    @ 2021-8-7 21:30:14

    C++ :

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        ll n,m,ans1,ans2,len,now,L,R,t;
        while(~scanf("%lld %lld",&n,&m))
        {
            ans1 = ans2 = 0;
            t = 1;
            /*for(int i = 1; i <= n; i++)
                ans1 += m % i;*/
            if(n >= m)
                ans2 = (n - m) * m,n = m;
            /*for(int i = 1; i <= m; i++)
                cout<<i<<":"<<m % i<<endl;*/
            L = 0;
            now = m;
            while(true)
            {
                t++;
                R = m / t + 1;
                if(R > now) break;
                if(R > n)
                {
                    now = m / t;
                    L = m % now;
                    continue;
                }
                len = now - R + 1;
                R = L + (len - 1) * (t - 1);
                if(now > n)
                {
                    L = m % n;
                    len = n - m / t;
                }
                ans2 += (R + L) * len / 2;
                now = m / t;
                if(!now) break;
                L = m % now;
            }
            for(int i = min(now,n); i >= 2; i--) //提前跳出来的数有可能大于n;
                ans2 += m % i;
            cout<<ans2<<endl;
        }
    }
    
    • 1

    信息

    ID
    110
    时间
    1000ms
    内存
    128MiB
    难度
    3
    标签
    递交数
    48
    已通过
    25
    上传者