# bzoj1041

y^2=(r-x)(r+x)  （r-x)(r+x)要是完全平方数

 1 var d,dd,r,ans,a:int64;
2     i,m:longint;
3     b:double;
4
5 function gcd(a,b:int64):int64;
6   begin
7     if b=0 then exit(a)
8     else exit(gcd(b,a mod b));
9   end;
10
11 function check(a,b:double):boolean;
12   var x,y:int64;
13   begin
14     if b=trunc(b) then
15     begin
16       x:=int64(trunc(a))*int64(trunc(a));
17       y:=int64(trunc(b))*int64(trunc(b));
18       if (gcd(x,y)=1) and (a<>b) then exit(true);
19     end;
20     exit(false);
21   end;
22
23 begin
25   m:=trunc(sqrt(2*r));
26   for i:=1 to m do
27   begin
28     d:=int64(i);
29     if 2*r mod d=0 then
30     begin
31       a:=0;
32       while (a<trunc(sqrt(r/d))) do
33       begin
34         inc(a);
35         b:=sqrt((2*r/d)-a*a);
36         if check(a,b) then inc(ans);
37       end;
38       dd:=2*r div d;
39       if dd<>d then
40       begin
41         a:=0;
42         while (a<trunc(sqrt(r/dd))) do
43         begin
44           inc(a);
45           b:=sqrt(2*r/dd-a*a);
46           if check(a,b) then inc(ans);
47         end;
48       end;
49     end;
50   end;
51   writeln(ans*4+4);
52 end.
View Code

posted on 2014-10-16 22:31  acphile  阅读(84)  评论(0编辑  收藏