你若不想做,你会找个借口;你若想做,你会找个办法。
参考程序:
var
a,b,x,y,k:longint;
function exgcd(a,b:longint;var x,y:longint):longint;
var
t:longint;
begin
if b=0 then
begin
x:=1;
y:=0;
exit(a);
end;
exgcd:=exgcd(b,a mod b,x,y);
t:=x;
x:=y;
y:=t-(a div b)*y;
end;
begin
assign(input,'mod.in');reset(input);
assign(output,'mod.out');rewrite(output);
readln(a,b);
k:=exgcd(a,b,x,y);
writeln((x+b)mod b);
close(input);close(output);
end.