Free Multiplicative Inverse Modulo Calculator

am

Enter a and m, then click Calculate

Introducing the Multiplicative Inverse Modulo Calculator

In number theory and practical applications such as cryptography, random number generation, and programming contests, the need to find a modular multiplicative inverse arises frequently. An inverse modulo calculator automates this task: it determines the integer xx such that a×x≡1(modm)a \times x \equiv 1 \pmod{m} for a given base aa and modulus mm. This online free modular inverse finder relies on the extended Euclidean algorithm under the hood, delivering the answer in milliseconds even when mm is large.

The calculator’s interface keeps things straightforward. You provide the modulus mm (a positive integer) and the integer aa, and the tool computes gcd⁡(a,m)\gcd(a, m). If the greatest common divisor equals one, it returns the unique inverse in the range {1,2,…,m−1}\{1, 2, \dots, m-1\}; otherwise it reports that no inverse exists. This behavior is rooted in mathematical conditions that are explained in the sections below.

What Is the Modular Multiplicative Inverse?

Formally, an integer xx is called the modular multiplicative inverse of aa modulo mm if

a×x≡1(modm).a \times x \equiv 1 \pmod{m}.

Another way to phrase it is that the remainder of a×xa \times x upon division by mm must be exactly 11. For example, consider a=3a = 3 and m=7m = 7; the inverse is 55 because 3×5=153 \times 5 = 15 and 15 mod 7=115 \bmod 7 = 1.

Any solution xx can be shifted by multiples of mm: if xx is an inverse, then x+kmx + k m (for any integer kk) also satisfies the congruence. The calculator therefore presents the canonical representative from the set {1,2,…,m−1}\{1, 2, \dots, m-1\}, where the inverse is unique.

When Does an Inverse Exist?

The existence of a modular inverse hinges entirely on the relationship between aa and mm:

  • An inverse exists if and only if gcd⁡(a,m)=1\gcd(a, m) = 1, i.e., aa and mm are coprime (relatively prime).
  • No inverse exists when gcd⁡(a,m)>1\gcd(a, m) > 1.

When mm is prime, every non‑zero integer aa that is not a multiple of mm automatically satisfies gcd⁡(a,m)=1\gcd(a, m) = 1 and therefore possesses an inverse. For composite moduli, a simple test shows the failure: take a=3a = 3 and m=6m = 6. Since gcd⁡(3,6)=3\gcd(3, 6) = 3, no integer xx makes 3x≡1(mod6)3x \equiv 1 \pmod{6}. Checking the residues 3,0,3,0,33, 0, 3, 0, 3 for x=1,2,3,4,5x = 1, 2, 3, 4, 5 confirms that 11 never appears.

How to Use the Mod Inverse Calculator

The steps are minimal:

  1. Enter the modulus mm (a positive integer).
  2. Enter the integer aa.
  3. Press the compute button.

The tool first evaluates gcd⁡(a,m)\gcd(a, m). If the gcd is one, it runs the extended Euclidean algorithm to find the inverse and displays the result together with a brief explanation of the steps. If the numbers are not coprime, the calculator informs you that the inverse does not exist.

Because the algorithm runs in O(log⁡m)O(\log m) time, even moduli with dozens of digits are processed almost instantly.

Bézout’s Identity and the Extended Euclidean Algorithm

The most efficient method for computing a modular inverse is the extended Euclidean algorithm. This algorithm solves Bézout’s identity:

ax+my=gcd⁡(a,m).a x + m y = \gcd(a, m).

When aa and mm are coprime, gcd⁡(a,m)=1\gcd(a, m) = 1, and the identity becomes

ax+my=1.a x + m y = 1.

Taking the entire equation modulo mm eliminates the term mym y (it is a multiple of mm), leaving

ax≡1(modm).a x \equiv 1 \pmod{m}.

Hence the coefficient xx obtained by the algorithm is exactly the modular multiplicative inverse.

A Worked Example

Find the inverse of 77 modulo 1919. Applying the extended Euclidean algorithm:

19=2×7+5,19 = 2 \times 7 + 5, 7=1×5+2,7 = 1 \times 5 + 2, 5=2×2+1.5 = 2 \times 2 + 1.

Back‑substituting produces 1=3×19−8×71 = 3 \times 19 - 8 \times 7. Reducing modulo 1919 gives −8×7≡1(mod19)-8 \times 7 \equiv 1 \pmod{19}; converting the negative coefficient to a positive residue by adding 1919 yields 1111. Therefore 1111 is the inverse, because 7×11=77≡1(mod19)7 \times 11 = 77 \equiv 1 \pmod{19}.

Brute‑Force Alternative for Small Moduli

If the modulus is very small, one can find the inverse by trial and error: test every integer x=1,2,…,m−1x = 1, 2, \dots, m-1 until ax mod m=1a x \bmod m = 1. While this brute‑force method is easy to understand, it becomes impractical when mm grows, which is why professional tools and programming libraries all employ the extended Euclidean algorithm.

Why It Matters

The ability to compute modular inverses quickly is fundamental in several areas:

  • Cryptography: In RSA, the decryption exponent dd is the modular inverse of the encryption exponent ee modulo ϕ(n)\phi(n).
  • Programming: Many competitive programming problems and libraries require modular division, which is performed by multiplying by the inverse.
  • Mathematics: Solving linear congruences and constructing finite fields rely on the existence and efficient calculation of inverses.

FAQ

1. How can I compute the modular multiplicative inverse by hand?

For small moduli, test each x from 1 to m−1 until a·x mod m = 1. For larger moduli, use the extended Euclidean algorithm: it finds integers x and y such that a·x + m·y = gcd(a,m); when gcd=1, x is the inverse.

2. What condition must be met for a modular inverse to exist?

The inverse exists only when a and m are coprime, i.e., when gcd(a,m) = 1. If they share any common factor greater than 1, no integer x can satisfy a·x ≡ 1 (mod m).

3. Is the modular multiplicative inverse unique?

The inverse is unique modulo m: if x is a solution, then x + k·m (for any integer k) is also an inverse. However, the calculator returns the unique value in the set {1, 2, …, m−1}.

4. Why does the calculator prefer the extended Euclidean algorithm over brute force?

The extended Euclidean algorithm runs in O(log m) time, making it far faster than brute force for large m. It simultaneously checks whether an inverse exists and computes it by solving Bézout’s identity.

5. What happens if I enter numbers that are not coprime?

The calculator computes gcd(a,m) and, if it is greater than 1, reports that the modular multiplicative inverse does not exist for that pair of numbers.

How to Use

  1. Enter the integer a whose multiplicative inverse you want to find.
  2. Enter the modulus m. The inverse exists only if a and m are coprime (gcd = 1).
  3. Click Calculate to find the modular inverse x such that (a × x) mod m = 1.