proc mulinv(int a, b) int: int t, nt, r, nr, q, tmp; if b<0 then b := -b fi; if a<0 then a := b - (-a % b) fi; t := 0; nt := 1; r := b; nr := a % b; while nr /= 0 do q := r / nr; tmp := nt; nt := t - q*nt; t := tmp; tmp := nr; nr := r - q*nr; r := tmp od; if r>1 then -1 elif t<0 then t+b else t fi corp proc show(int a, b) void: int mi; mi := mulinv(a, b); if mi>=0 then writeln(a:5, ", ", b:5, " -> ", mi:5) else writeln(a:5, ", ", b:5, " -> no inverse") fi corp proc main() void: show(42, 2017); show(40, 1); show(52, -217); show(-486, 217); show(40, 2018) corp