Modular Inverse

In modular arithmetic, a modular inverse exists for every , such that , if and only if (i.e., and must be coprime). The easiest way to find the greatest common divisor of two integers is using Euclid’s Algorithm, which recursively divides the integers based on the identity

and terminates when the remainder becomes zero.

The Extended Euclidean Algorithm not only computes , but also performs a backward pass to find (not necessarily distinct) integers , which satisfy Bezout’s identity,

It is executed as follows:

  1. Set the starting pair and .
  2. While (forward pass / standard Euclid):
  3. Let and .
  4. Now set and .
  5. Then, for (backward pass):
  6. Let and .
  7. When you are done, you will have the coefficients and factor that solve .

Proof & Intuition

Inversion

Here is where modular arithmetic gets a little tricky. We will go ahead and prove necessity and sufficiency for inversion:

  1. Sufficiency (): Since and are coprime, neither can divide the other. Enter Bezout’s Identity, which states that . We take both sides modulo , and obtain As such, we find that is the inverse of . You can think of as the “correction term” for the linear Diophantine, although it has no modular meaning unless we rearrange and , such that is the inverse of .
  2. Necessity () We have that . Then by definition of modular congruence, there exists an integer (quotient) such that: . Rearranging, per Bezout’s identity.

Intuitively, why is the condition for modular inversion? Think about it this way: if and shared a common factor , then that must be able to divide any linear combination of and .

Euclid’s Algorithm

The statement above will help us prove the fact that . In order to see it, express . Then, if divides and , then also divides , as well as when rearranging. Now plug and and try it yourself.

Extended Euclid

Now, let’s switch gears to extended Euclid.

Properties

(Divisibility) Let , such that . If , then .

(Prime Modulus) If is a prime number, all numbers have a modular inverse.

(Fermat’s Little Theorem) For all primes , if , and for all .

Examples

(Easy) Finding Inverses

We will investigate the existence and uniqueness of inverses:

(Easy) Inverse Proofs

Prove or disprove the following statements:

(Medium) Proving the Fundamental Theorem of Arithmetic

Prove that every integer greater than 1 can be written uniquely as a product of (not necessarily unique) prime numbers, up to the order of the factors.

(Medium) Iterative EGCD!?

In this example, we explore an alternative way of finding the triple in an iterative, rather than a recursive way.

How Many Solutions?

Consider the equation for prime . In the below three parts, all values , , are defined as values in the range . In addition, include justification for your answers to all the subparts of this problem.