Cod sursa(job #1262969)

Utilizator costeasaracostea sara costeasara Data 13 noiembrie 2014 19:27:27
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.53 kb
program fractii;
var f,g:text;i,j,n,nr,x,y:longint;
begin
assign (f,'fractii.in'); reset (f);
assign (g,'fractii.out'); rewrite (g);
while not eof(f) do
begin
readln (f,n);
nr:=2*n-1;
for i:=2 to n do
for j:=2 to n do
begin
if abs(i-j)=1 then  nr:=nr+1
              else if (i<>j) and ((i mod j<>0) or (j mod i<>0)) or (i mod 2=0) and (j mod 2=0) then
              begin x:=i; y:=j;
while x<>y  do
if x>y then x:=x-y
       else y:=y-x;
if y=1 then nr:=nr+1;
end;
end;
writeln (g,nr);
end;
close (f);
close (g);
end.