Pagini recente » Cod sursa (job #963522) | Cod sursa (job #2059270) | Cod sursa (job #1399341) | Cod sursa (job #1629850) | Cod sursa (job #293411)
Cod sursa(job #293411)
Program Algoritmul_lui_Euclid_extins;
type semn=(nedeterminat,minus,plus);
var t,i:byte;
a,b,c,d,x,y:longint;
semnx:semn;
function cmmdc(a,b:longint):longint;
var r:longint;
begin
while b<>0 do
begin
r:=a mod b;
a:=b;
b:=r;
end;
cmmdc:=a;
end;
begin
randomize;
assign(input,'euclid3.in');
reset(input);
assign(output,'euclid3.out');
rewrite(output);
readln(t);
for i:=1 to t do
begin
readln(a,b,c);
if a=0 then begin
if b=0 then writeln(random(65535),' ',random(65535))
else if c mod b=0 then writeln(random(65535),' ',c div b)
else writeln('0 0');
continue;
end
else if b=0 then begin
if c mod a=0 then writeln(c div a,' ',random(65535))
else writeln('0 0');
continue;
end;
d:=cmmdc(a,b);
if c mod d<>0 then writeln('0 0')
else
begin
a:=a div d;
b:=b div d;
c:=c div d;
x:=0;
semnx:=nedeterminat;
while semnx=nedeterminat do
begin
inc(x);
if(c-a*x)mod b=0 then semnx:=plus
else if (c-a*(-x))mod b=0 then semnx:=minus;
end;
if semnx=minus then x:=-x;
y:=(c-a*x)div b;
writeln(x,' ',y);
end;
end;
close(input);
close(output);
end. {nimeni nu vede ce am scris aici}