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.