chickadee » math » modular-inverse

modular-inverse a nprocedure
a
integer
b
integer

Returns the inverse of a modulo n if a and n are coprime, otherwise raises an error. The modulus n must be positive, and a must be nonzero.

Formally, if a and n are coprime, b = (modular-inverse a n) is the unique natural number less than n such that (* a b) = 1 (mod n).

> (modular-inverse 2 5)
3
> (modulo (* 2 3) 5)
1

Wikipedia: Multiplicative Inverse