SDUT 2022 Summer Individual Contest - 4 (补题)

题目链接:

Fear Factoring - Gym 101652P - Virtual Judge (vjudge.net)

概述:F(x)表示1~x中所有数的所有因子的总和,计算F(b)-F(a)

分析:整除分块的思想

 关于整除分块的传送门:整除分块 - SugarT 

(这里还放自己博客多不要脸呐)

#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define PI acos(-1)
#define SugarT ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1e5+10;
const int M=510;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps = 1e-6;

ULL get_sum(ULL x)
{

    ULL ans=0;
    for(ULL l=1,r;l<=x;l=r+1)
    {
        r=x/(x/l);
        ans+=(x/l)*(r-l+1)*(l+r)/2;
    }
    return ans;

}

void solve()
{

    ULL a,b;
    cin >> a >> b;
    cout << get_sum(b)-get_sum(--a) << endl;

}

int main()
{
    SugarT
    int T=1;
        //cin >> T;
    while(T--)
        solve();

    return 0;
}

posted @ 2022-07-08 17:26  MrSugarT  阅读(43)  评论(0编辑  收藏  举报