Cod sursa(job #1418923)

Utilizator ButnaruButnaru George Butnaru Data 14 aprilie 2015 13:27:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.52 kb
program euclid;
var a,b,x,y,z,d,n,i,c:longint;
    f1,f2:text;
function gcd(a,b:longint):longint;
begin
if b=0 then begin
x:=1;
y:=0;
gcd:=a;
end else begin
gcd:=gcd(b,a mod b);
z:=x; x:=y;
y:=z-(a div b)*y;
end;
end;
begin
assign (f1,'euclid3.in');
assign (f2,'euclid3.out');
reset (f1);
rewrite (f2);
readln (f1,n);
for i:=1 to n do begin
 readln (f1,a,b,c);
 d:=gcd(a,b);
 if c mod d<>0 then writeln (f2,0,' ',0) else
  writeln (f2,(c div d)*x,' ',(c div d)*y);
end;
close (f1);
close (f2);
end.