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;
}
posted @ 2019-02-07 09:36  水题收割者  阅读(129)  评论(0编辑  收藏  举报