Cod sursa(job #89440)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 6 octombrie 2007 20:54:03
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.99 kb
var n,i,j,k,s:longint;
    f,g:text;
function ireductibil(x,y:longint):boolean;
         {Functia da valoarea true daca fractia x\y este ireductibila
         si false in caz contrar}
         var a,i:longint;
             ir:boolean;
         begin
              ir:=true;
              if (x<>1) or (y<>1) then begin
                 if y>=x then a:=x
                 else a:=y;
                 i:=1;
                 while (i<a) and (ir=true) do begin
                     i:=i+1;
                     if (x mod i=0) and (y mod i=0) then ir:=false;
                 end;
              end;
              ireductibil:=ir;
         end;
begin
     s:=0;
     k:=0;
     assign(f,'fractii.in');
     reset(f);
     readln(f,n);
     close(f);
     for i:=1 to n do
         for j:=1 to n do begin
             k:=k+1;
             if ireductibil(i,j)=true then s:=s+1;
         end;
     assign(g,'fractii.out');
     rewrite(g);
     writeln(g,s);
     close(g);
end.