SQUARES - Hình vuông

Tác giả: RR

Ngôn ngữ: Pascal

{$R+,Q+}
var
  n,u,sum:longint;
  kq:int64;
function gcd(a,b:longint):longint;
begin
  if (a=0) or (b=0) then exit(a+b)
  else if (a<b) then exit(gcd(b,a))
  else exit(gcd(b,a mod b));
end;
procedure count;
var
  i:longint;
begin
  for i:=1 to sum div 2 do
    if gcd(i,sum-i)=1 then inc(kq);
end;
begin
  read(n);
  kq:=0;
  for u:=trunc(sqrt(n)) downto 1 do
  if n mod u=0 then
    begin
      sum:=n div u+1;
      count;
      if u*u=n then continue;
      sum:=u+1;
      count;
    end;
  writeln(kq);
end.

Download