Cod sursa(job #109951)

Utilizator alexrusuRusu Alexandru alexrusu Data 25 noiembrie 2007 12:59:34
Problema Ecuatie Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 1, Clasele 5-8 Marime 0.82 kb
program ecuatie;
var d1,d2,i,a,b,c,k,p1,q1,p2,q2:longint;
    p,q:array[1..100000] of longint;
    s1, s2:string;
    f,g:text;
begin
  assign(f,'ecuatie.in');
  assign(g,'ecuatie.out');
  reset(f);
  rewrite(g);
  readln(f,a,b,c,k);
  i:=0;
  for d1:=-a to a do
    if (d1<>0) and (a mod d1=0) then
      for d2:=-c to c do
        if (d2<>0) and (c mod d2=0) then
          begin
            p1:=d1;
            p2:=a div d1;
            q1:=d2;
            q2:=c div d2;
            if p1*q2+p2*q1=b  then
              begin
                i:=i+1;
                p[i]:=p1;
                q[i]:=q1;
              end;
          end;
  if(q[k]>0)then
    s1:='+';
  if(c div q[k]>0)then
    s2:='+';
  writeln(g,'(',p[k],'x',s1,q[k],')(', a div p[k],'x',s2,c div q[k],')');
  close(f);
  close(g);
end.