Cod sursa(job #25524)

Utilizator al3csutzuSirbu Alexandru al3csutzu Data 4 martie 2007 12:50:02
Problema Puteri Scor 0
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 10-a Marime 1.24 kb
program puteri;
var a,b,c,k:array [1..100000] 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 j:=2 to p do
      if ((a[i] mod j=0) or (a[i]=0)) and ((b[i] mod j=0) or (b[i]=0))and ((c[i] mod j=0) or (c[i]=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;
          if p<>1 then
          for t:=2 to p do
          if ((as mod t=0) or (as=0)) and ((bs mod t=0) or (bs=0))and ((cs mod t=0) or (cs=0))then p:=65;
          if p=65 then nr:=nr+1;
        end;
      end;
  writeln(g,nr);
  close(f); close(g);
end.