Pagini recente » Cod sursa (job #1618832) | Cod sursa (job #693833) | Cod sursa (job #2752700) | Cod sursa (job #1469367) | Cod sursa (job #2900510)
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
AssignFile(fin, C_IN_FNAME);
AssignFile(fout, C_OUT_FNAME);
Reset(fin);
Readln(fin, n);
Rewrite(fout);
while not Eof(fin) do
begin
Readln(fin, a, b, c);
Euclid3(a, b, d, x, y);
if c mod d <> 0 then
Writeln(fout, '0 0')
else
begin
Writeln(fout, IntToStr(x * (c div d)), ' ', IntToStr(y * (c div d)));
end;
end;
CloseFile(fin);
CloseFile(fout);
end.