![1041: [HAOI2008]圆上的整点 - BZOJ 1041: [HAOI2008]圆上的整点 - BZOJ](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Description
求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。
Input
r
Output
整点个数
Sample Input
4
Sample Output
4
HINT
n<=2000 000 000
不会做,膜拜神犇的题解
var
r:int64;
ans,d:longint; function gcd(a,b:int64):int64;
var
t:int64;
begin
while b<> do
begin
t:=a mod b;
a:=b;
b:=t;
end;
exit(a);
end; procedure slove(r:int64);
var
i:longint;
j:int64;
begin
for i:= to trunc(sqrt(r)) do
begin
j:=trunc(sqrt(r-i*i));
if i>=j then break;
if (int64(i)*i+int64(j)*j=r) and (gcd(i,j)=) then inc(ans);
end;
end; begin
read(r);
r:=r<<;
for d:= to trunc(sqrt(r)) do
begin
if r mod d<> then continue;
slove(r div d);
if int64(d)*d=r then break;
slove(d);
end;
write(ans<<+);
end.