AcWing 199. 余数之和 (取模运算,公式化简)
程序员文章站
2022-07-12 13:41:55
...
signed main()
{
int n,k; cin>>n>>k;
ll ans=1ll*n*k;
for(int l =1;l<=n;)
{
if(k/l==0) break;
int r = min((k/(k/l)),n);
ans -= 1ll*(k / l) * (l + r) * (r - l + 1) / 2;
l = r+1;
}
cout<<ans<<endl;
return 0;
}