BZOJ 1257 [CQOI2007]余数之和sum
题解:a%b=a-[a/b]*b;
ans=n*k-sigma([k/i]*i]);
[k/i]有sqrt(k)种取值
last=k/(k/last);
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long Lint; int n,m; Lint ans; int main(){ cin>>n>>m; ans=1LL*n*m; if(m>n){ int last; for(int i=1;i<=n;i=last+1){ last=min(n,m/(m/i)); ans=ans-(last-i+1)*1LL*(last+i)*(m/i)/2; } }else{ int last; for(int i=1;i<=m;i=last+1){ last=m/(m/i); ans=ans-(last-i+1)*1LL*(last+i)*(m/i)/2; } } cout<<ans<<endl; return 0; }
致歉:笔者已经意识到这是一篇几乎没有价值的文章,给您的阅读带来不好的体验,并且干扰了您的搜索环境,非常抱歉!