NC218398 小G的约数

https://ac.nowcoder.com/acm/problem/218398
数论分块
在1~x 内,因数为 i 的数有 x/i 个,则约数和就是 x/i * i。
则G(n)就是

\[\sum_{i=1}^n i\times \lfloor \frac{n}{i} \rfloor \]

点击查看代码
#include <bits/stdc++.h>
using namespace std;

#define int long long

int G(int n)
{
    int l=1,r=0,ans=0;
    while(l<=n){
        r = n / (n/l);
        ans += (r-l+1) * (n/l) * (l + r) / 2;
        l = r + 1;
    }
    return ans;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int q;cin >> q;
    cout << G(G(q)) << endl;

    return 0;
}


posted @ 2022-07-16 13:37  HIVM  阅读(19)  评论(0编辑  收藏  举报