Cod sursa(job #25411)

Utilizator al3csutzuSirbu Alexandru al3csutzu Data 4 martie 2007 12:31:04
Problema Puteri Scor 0
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 10-a Marime 1.15 kb
program puteri;
var a,b,c,k:array [1..10000] of byte;
cs,bs,as:byte;
n,i,p,nr,t,j:longint;
f,g:text;
begin
  assign(f,'puteri.in'); assign(g,'puteri.out');
  reset(f); rewrite(g);
  read (f,n);
  for i:=1 to n do
  begin
    read (f,a[i],b[i],c[i]);
    k[i]:=0;
    if (a[i]>b[i]) and (a[i]>c[i]) then p:=a[i]
       else if (b[i]>a[i]) and (b[i]>c[i]) then p:=b[i] else p:=a[i];
    if p<>1 then
    for i:=2 to p do
      if (a[i] mod p=0) and (b[i] mod p=0) and (c[i] mod p=0) then p:=n;
    if p=n then k[i]:=1;
  end;
  nr:=0;
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if (k[i]=1) and (k[j]=1) then nr:=nr+1
      else
      begin
        as:=a[i]+a[j]; cs:=c[i]+c[j]; bs:=b[i]+b[j];
        if (((as=0) and (bs=0)) or ((as=0) and (cs=0)) or ((bs=0) and (cs=0))) then nr:=nr+1
        else
        begin
          if (as>bs) and (as>cs) then p:=as
            else if (bs>as) and (bs>cs) then p:=bs else p:=as;
          for t:=1 to p do
            if (as mod p=0) and (bs mod p=0) and (cs mod p=0) then p:=65;
          if p=65 then nr:=nr+1;
        end;
      end;
  writeln(g,nr);
  close(f); close(g);
end.