def inv_step
import bend-collections@1.0.0.0/src/math/natural.bend as Naturalimport Base
300# Extended Euclid on (m, a mod m) keeping only the coefficient of a, mod m:
301# a * s0 == r0 and a * s1 == r1 (mod m). The remainders are gcd's.
302def inv_step(+m: Nat, +q: Nat, +s0: Nat, +s1: Nat) -> Nat:
303 Nat.mod(Nat.add(s0, Nat.sub(m, Nat.mod(Nat.mul(q, s1), m))), m)