Pagini recente » Cod sursa (job #2441618) | Cod sursa (job #2103743) | Cod sursa (job #1126479) | Cod sursa (job #1539168) | Cod sursa (job #1501856)
var f:text;
a,b:longint;
x,y,d:longint;
procedure euclid(a,b:longint;var d,x,y:longint);
var x0,y0:longint;
begin
if b=0 then
begin
d:=a;
x:=1;
y:=0
end
else
begin
euclid(b,a mod b,d,x0,y0);
x:=y0;
y:=x0-(a div b)*y0
end;
end;
begin
assign(f,'inversmodular.in');
reset(f);
readln(f,a,b);
close(f);
euclid(a,b,d,x,y);
while x<0 do inc(x,b);
assign(f,'inversmodular.out');
rewrite(f);
writeln(f,x);
close(f);
end.