Pagini recente » Cod sursa (job #2735502) | Cod sursa (job #2898078) | Cod sursa (job #1043369) | Cod sursa (job #1280392) | 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.