p2261 [CQOI2007]余数求和
分析
https://zzlzk.blog.luogu.org/solution-p2261
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main(){
long long Ans,n,k,le=1,ri;
scanf("%lld%lld",&n,&k);
Ans=n*k;
for(;le<=n;le=ri+1){
if(k/le)ri=min(n,k/(k/le));
else ri=n;
Ans-=(k/le)*((ri-le+1)*(ri+le)/2);
}
cout<<Ans;
return 0;
}