Function reference · Math

modinv

Returns the inverse of a modulo m: the x for which a·x leaves remainder 1.

The inverse exists only when a and m have no common factor; otherwise it is an error.

Notation

modinv(arg1, arg2)

Write it in an expression: nerdamer('modinv(3,7)'), or in the Playground.

Examples

3·5 = 15 leaves 1 modulo 7.

modinv(3,7)
// → 5
Open in Playground

The inverse of 10 modulo 17.

modinv(10,17)
// → 12
Open in Playground

← Back to Function reference