题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1257
( n\%i = n - left lfloor n/i ight floor * i )
注意 n<k 时当前块的右端点可能超过 n !
#include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; int n,k;ll ans; int main() { scanf("%d%d",&n,&k); int lm=min(n,k); for(int i=1,j,d;i<=lm;i=j+1) { d=k/i; j=min(k/d,n);//min!!! ans+=(ll)d*(i+j)*(j-i+1)>>1ll; } printf("%lld ",(ll)n*k-ans); return 0; }