除法分块
- k % i = k - (k / i) * i
- 当$n < k$ 的时候分块右边r = k / (k / l)可能会大于n,会出问题。所以需要与右边界n取最小值
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, k;
scanf("%lld%lld",&n,&k);
ll l, r, ans = n * k;
for(l = 1; l <= n; l = r + 1)
{
if(k / l) r = min(k / (k / l),n);
else r = n;
ll q = k / l;
ll a1 = l * q, an = r * q;
ans -= (a1 + an) * (r - l + 1) / 2;
}
cout << ans;
}