Pagini recente » Cod sursa (job #14276) | Cod sursa (job #309556) | Cod sursa (job #990391) | Cod sursa (job #2700782) | Cod sursa (job #1417634)
const
f1='inversmodular.in';
f2='inversmodular.out';
var
a,b,x,y:longint;
procedure euclid(a,b:longint;var x,y:longint);
var x1,y1:longint;
begin
if b=0 then
begin
x:=1;
y:=0;
end
else
begin
euclid(b,a mod b,x1,y1);
x:=y1;
y:=x1-(a div b)*y1;
end;
end;
begin
assign(input,f1); reset(input);
assign(output,f2); rewrite(output);
readln(a,b);
close(input);
euclid(a,b,x,y);
while x<0 do
inc(x,b);
write(x);
close(output);
end.