1~N的约数之和(数论,分块)

https://ac.nowcoder.com/acm/contest/114408/A

数论知识:https://oi-wiki.org/math/

image

重要的转换芝士

挺板的

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

signed main()
{
    int n;
    cin>>n;
    int l=1,r=0;
    int res=0;
    while(l<=n)
    {
        r=n/(n/l);
        res=res+(n/l)*(r-l+1ll);
        l=r+1;
    }
    cout<<res;
    return 0;
}
posted @ 2025-07-23 19:56  ha000star  阅读(17)  评论(0)    收藏  举报