Pagini recente » Cod sursa (job #2998531) | Cod sursa (job #2947247) | Cod sursa (job #484877) | Cod sursa (job #1945545) | Cod sursa (job #2900512)
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
try
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);
except
on E:Exception do
Writeln('File ', C_IN_FNAME, ' could not be created because: ', E.Message);
end;
end.