原式=k*n-∑(k/i)*i(1<=i<=n),典型的分块处理。
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long k,n,ans; int main() { scanf("%lld%lld",&n,&k); ans=k*n; long long left,right;left=1; while ((k/left!=0) && (left<=n)) { right=min(k/(k/left),n); ans-=(left+right)*(right-left+1)*(k/right)/2; left=right+1; } printf("%lld\n",ans); return 0; }