Pagini recente » Cod sursa (job #2698970) | Cod sursa (job #1581042) | Cod sursa (job #1089140) | Cod sursa (job #2243058) | Cod sursa (job #1418925)
program inversmodular;
var a,b,c,x,y,z,d:longint;
function gcd(a,b:longint):longint;
begin
if b=0 then begin x:=1; y:=0; gcd:=a; end else begin
gcd:=gcd(b,a mod b);
z:=x; x:=y;
y:=z-(a div b)*x
end;
end;
begin
assign (input,'inversmodular.in');
assign (output,'inversmodular.out');
reset (input);
rewrite (output);
readln (a,b);
d:=gcd(a,b);
while x<0 do x:=x+b;
writeln (x);
close (input);
close (output);
end.