众所周知,这个式子就是\(\sum_{i=1}^n(k-i*\lfloor\frac{k}{i}\rfloor)\)
也就是\(n*k-\sum_{i-1}^n(i*\lfloor\frac{k}{i}\rfloor)\)
右边的东西用数论分块+等差数列搞一下就可以了
数论分块的每一块的右边界是\(\lfloor\frac{k}{\lfloor\frac{k}{i}\rfloor}\rfloor\)
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,k;
long long ans;
int main(){
scanf("%d%d",&n,&k);
ans=n*k;
long long r;
for(long long l=1;l<=n;l=r+1){
if(k/l!=0) r=min(k/(k/l),n);
else r=n;
ans-=(k/l)*(r-l+1)*(l+r)/2;
}
cout<<ans;
return 0;
}