题目大意:给你$R(Rleqslant10^{14})$,求:
$$
sumlimits_{xinmathbb{Z}}sumlimits_{yinmathbb{Z}}[x^2+y^2leqslant R](x^2+y^2)
$$
题解:明显可以发现这是对称的,所以可以只枚举四分之一,并且$x,yleqslantsqrt R$。所以式子成了$4sumlimits_{x=0}^{sqrt R}sumlimits_{y=1}^{sqrt R}[x^2+y^2leqslant R](x^2+y^2)$。这样就可以暴力枚举了,复杂度$O(R)$。
然后那个判断有点烦,去掉,变成$4sumlimits_{x=0}^{sqrt R}sumlimits_{y=1}^{sqrt{R-x^2}}(x^2+y^2)$
$$
egin{align*}
&4sumlimits_{x=0}^{sqrt R}sumlimits_{y=1}^{sqrt{R-x^2}}(x^2+y^2)\
=&4sumlimits_{x=0}^{sqrt R}(sqrt{R-x^2}x^2+sumlimits_{y=1}^{sqrt{R-x^2}}y^2)\
end{align*}\
令Y=sqrt{R-x^2}\
=4sumlimits_{x=0}^{sqrt R}(Yx^2+dfrac{Y(Y+1)(2Y+1))}6)\
$$
复杂度$O(sqrt R)$
卡点:无
C++ Code:
#include <cstdio> #include <cmath> const long long mod = 1e9 + 7, mod6 = mod * 6; long long R, ans; inline void reduce(long long &x) { x += x >> 63 & mod; } int main() { scanf("%lld", &R); for (long long x = sqrt(R), y; ~x; --x) { y = sqrt(R - x * x); reduce(ans += x * x % mod * y % mod - mod); reduce(ans += y * (y + 1) % mod6 * (2 * y + 1) / 6 % mod - mod); } printf("%lld ", ans * 4 % mod); return 0; }