invmod

invmod(a, b)

Try it yourself:

See also:

invmod(): modular multiplicative inverse

invmod(a, m) finds a number x such that a × x ≡ 1 (mod m). For example, invmod(3, 11) is 4 because 3 × 4 leaves remainder 1 after division by 11.

When an inverse exists

An inverse exists exactly when a and m are coprime: their greatest common divisor is 1. This condition is central to modular arithmetic and cryptographic algorithms.

Related number tools

Check coprimality with gcd(). Use mod() to verify the remainder, pow() for powers, and isPrime() when considering prime moduli. factorial() is not a substitute for modular inversion.

Input caution

Use integer arguments and a positive modulus greater than one. If gcd(a, m) is not 1, no multiplicative inverse exists.

Try Invmod in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions