T2:圆点

思考难度:提高?

代码难度:普及?

首先有结论:半径 R \sqrt{R} R 的圆经过的整点数是 4 d R χ ( d ) 4\sum_{d|R}\chi(d) 4dRχ(d),其中 χ ( d ) = 1 <mtext>   </mtext> ( d &NegativeThinSpace;&NegativeThinSpace; m o d &ThinSpace;&ThinSpace; 4 = 1 ) , <mtext>   </mtext> 1 <mtext>   </mtext> ( d &NegativeThinSpace;&NegativeThinSpace; m o d &ThinSpace;&ThinSpace; 4 = 3 ) , <mtext>   </mtext> 0 <mtext>   </mtext> ( d &NegativeThinSpace;&NegativeThinSpace; m o d &ThinSpace;&ThinSpace; 2 = 0 ) . \chi(d)=1~(d\!\!\mod 4=1),~-1~(d \!\!\mod 4 =3),~0~(d \!\!\mod 2=0). χ(d)=1 (dmod4=1), 1 (dmod4=3), 0 (dmod2=0).

所以答案是

4 <munderover> i = 1 R </munderover> i <munder> d i </munder> χ ( d ) 4\sum_{i=1}^{R}i\sum_{d|i}\chi(d) 4i=1Ridiχ(d)

= 4 <munderover> d = 1 R </munderover> d × χ ( d ) <munderover> i = 1 n d </munderover> i =4\sum_{d=1}^{R}d\times \chi(d)\sum_{i=1}^{\lfloor{\frac{n}{d}}\rfloor}i =4d=1Rd×χ(d)i=1dni

然后就可以 O ( R ) O(\sqrt{R}) O(R )计算了。