Pagini recente » Cod sursa (job #1035906) | Cod sursa (job #2820824) | Cod sursa (job #1794178) | Cod sursa (job #1770554) | Cod sursa (job #2900513)
program euclid3;
{$MODE objfpc}{$H+}{$J-}
uses sysutils;
procedure Euclid3(a, b: longint; out d: longint; out x: longint; out y: longint);
var
newX, newY: longint;
begin
if b = 0 then
begin
d := a;
x := 1;
y := 0;
end
else
begin
Euclid3(b, a mod b, d, x, y);
newX := y;
newY := x - y * (a div b);
x := newX;
y := newY;
end;
end;
const
C_IN_FNAME = 'euclid3.in';
C_OUT_FNAME = 'euclid3.out';
var
fin, fout: text;
n, a, b, c, d, x, y : longint;
begin
Assign(fin, C_IN_FNAME); Reset(fin);
Assign(fout, C_OUT_FNAME); Rewrite(fout);
read(fin, n);
while not Eof(fin) do
begin
read(fin, a, b, c);
euclid3(a, b, d, x, y);
if c mod d=0 then
Writeln(fout, x * (c div d), ' ', y * (c div d))
else
Writeln(fout, '0 0');
end;
Close(fin); Close(fout);
end.