Cod sursa(job #12186)

Utilizator QbyxEros Lorand Qbyx Data 3 februarie 2007 09:27:35
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.58 kb
var
  n, r, i, j: longint;
  f: text;

function Egyxusitheto(a,b:longint):boolean;
begin
  Egyxusitheto:=true;
  while a <> b do
    begin
      if a > b then Dec(a, (a div b) * b) else Dec(b, (b div a) * a);
      if a = 0 then inc(a, b);
      if b = 0 then inc(b, a);
    end;
    if a = 1 then egyxusitheto:=false;
end;

begin
  Assign(f, 'fractii.in');
  Reset(f);
  ReadLn(f, n);
  Close(f);
  for i :=  2 to n do
    for j := 2 to n do
      If Not(Egyxusitheto(i,j)) then inc(r);
  Assign(f, 'fractii.out');
  ReWrite(f);
  Writeln(f, r+2*n-1);
  Close(f);
end.