bzoj1257: [CQOI2007]余数之和sum
乱搞。。一眼看上去没思路,%题解,结果居然是找规律!?
29/10=2(9) 29/11=2(7) 29/12=2(5) 29/13=2(3) 29/14=2(1) 等差数列走起!
#include<cstdio> #include<iostream> #include<cstring> using namespace std; typedef long long LL; int main() { LL n,k,ans=0;//k除以l~r的商是相等的 scanf("%lld%lld",&n,&k); for(LL l=1,r;l<=n;l=r+1,r=n) { LL d=k/l;//商 if(d!=0)r=min(k/d,n); ans+=(k-d*l+k-d*r)*(r-l+1)/2; } printf("%lld\n",ans); return 0; }
pain and happy in the cruel world.