Cod sursa(job #25137)

Utilizator ldocPopDragos ldoc Data 4 martie 2007 11:01:03
Problema Puteri Scor 10
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 0.8 kb
var n,i,j,c1,rez,a1,b1,cmdc:longint;
    a,b,c:array [1..100000] of longint;

function cmmdc (var x,y:longint):longint;
var r:longint;
begin
 if (x=1) or (y=1) then begin cmmdc:=1; exit; end;
 r:=x mod y;
 while r>0 do begin
  x:=y;
  y:=r;
  r:=x mod y;
 end;
 cmmdc:=y;
end;

begin
 assign (input,'puteri.in'); reset (input);
 assign (output,'puteri.out'); rewrite (output);
  readln (n);
  for i:=1 to n do
   readln (a[i],b[i],c[i]);
  for i:=1 to n-1 do
   for j:=i+1 to n do begin
    a1:=a[i]+a[j]; b1:=b[i]+b[j];
    if (a1<>0) and (b1<>0) then cmdc:=cmmdc (a1,b1)
    else cmdc:=abs (a1-b1);
    c1:=c[i]+c[j];
    if c1<>0 then
     if cmmdc (c1,cmdc)>1 then inc (rez)
    else
     if (cmdc>1) then inc (rez);
   end;
 writeln (rez);
 close (input); close (output);
end.