Pagini recente » Cod sursa (job #287165) | Cod sursa (job #3132982) | Cod sursa (job #3223112) | Cod sursa (job #1540309) | Cod sursa (job #1100691)
var a,b:text;
m,n,d,i,x,y,cm,e,l:longint;
function r(j:longint):longint;
begin
if j=0 then r:=m else
if j=1 then r:=n else
r:=(r(j-2)) mod (r(j-1));
end;
function q(j:longint):longint;
begin
if j=0 then q:=0 else
if j=1 then q:=(m div n) else
q:=(r(j-1)) div (r(j));
end;
function s(j:longint):longint;
begin
if j=0 then s:=1 else
if j=1 then s:=0 else
s:=s(j-2)-s(j-1)*q(j-1);
end;
function t(j:longint):longint;
begin
if j=0 then t:=0 else
if j=1 then t:=1 else
t:=t(j-2)-t(j-1)*q(j-1);
end;
function euclid(m,n:longint):longint;
begin
if (m>0) and (n>0) then euclid:=euclid(n, m mod n) else
if m=0 then euclid:=n else euclid:=m;
i:=i+1;
end;
begin
assign(a,'euclid3.in');
reset(a);
assign(b,'euclid3.out');
rewrite(b);
read(a,e);
for l:=1 to e do
begin
i:=0;
read(a,m,n,d);
cm:=euclid(m,n);
if cm=0 then cm:=1;
if (d mod cm)=0 then
begin
x:=(d div cm)*s(i-1);
y:=(d div cm)*t(i-1);
end else
begin
x:=0;
y:=0;
end;
writeln(b,x,' ',y);
end;
close(a);
close(b);
end.