A modular multiplicative inverse is the number that reverses multiplication under a modulus. Enter integers a and m to find the unique representative x in the range from 0 to m − 1.
\[ax \equiv 1 \pmod m\]
When Does an Inverse Exist?
An integer may be inverted modulo m exactly when it is coprime to m:
\[ \gcd(a,m)=1. \]If the greatest common divisor is larger than 1, every product ax shares that divisor and therefore cannot be congruent to 1 modulo m. The calculator reports this case as having no solution.
Why the Extended Euclidean Algorithm Works
The extended Euclidean algorithm computes Bézout coefficients s and t satisfying
\[ as+mt=\gcd(a,m). \]When the gcd is 1, reducing this identity modulo m removes the term mt:
\[ as \equiv 1 \pmod m. \]Thus s is an inverse of a. Normalizing s modulo m produces the standard nonnegative representative. For example,
\[ 17\cdot38=646=15\cdot43+1, \]so \(17^{-1}\equiv38\pmod{43}\). The implementation uses JavaScript BigInt, preserving exact integer arithmetic beyond the 32-bit and safe-number limits.