Cod sursa(job #1420309)

Utilizator ButnaruButnaru George Butnaru Data 18 aprilie 2015 10:02:22
Problema Algoritmul lui Euclid extins Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.51 kb
program euclid3;
var n,a,b,c,z,x,y,i,d: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.