The Timpson Lyceum seal

The Timpson Lyceum · Discrete Math (2025)

Modular Arithmetic, Chinese Remainder Theorem, and Factoring - Lecture 20 (Discrete Math)

Modular Arithmetic, Chinese Remainder Theorem, and Factoring – Lecture 20

Overview

This lecture completes the study of modular arithmetic and opens the topic of factoring. We define division in Zn\mathbb{Z}_n via multiplicative inverses, discover that — unlike on the real numbers — most elements have no inverse, and prove the central fact that an element is invertible exactly when it is relatively prime to nn. We then use the extended Euclidean algorithm to compute inverses (and hence divide) even in large moduli, solve single congruences and systems of congruences (the Chinese Remainder Theorem in action). Finally we introduce prime factorization, state the Fundamental Theorem of Arithmetic, and prove the prime-divisibility lemmas (Euclid's lemma and its generalization) that the uniqueness proof will rest on.

Key Concepts

The set Zn\mathbb{Z}_n. Zn={0,1,2,…,n−1}\mathbb{Z}_n = \{0, 1, 2, \dots, n-1\}, the first nn natural numbers. Note the largest element is n−1n-1, one less than nn.

Addition and multiplication mod nn. Both operations piggyback on ordinary arithmetic and then reduce:

Algebraic properties (for n≥2n \ge 2, so 0,1∈Zn0,1 \in \mathbb{Z}_n). These are inherited from the reals:

Subtraction. Defined from addition: a−ba - b is the unique xx solving a+x=ba + x = b. It turns out a−b=(a−b) mod na - b = (a - b) \bmod n, matching the way addition is defined.

Reciprocal / multiplicative inverse. For a∈Zna \in \mathbb{Z}_n, we call bb the reciprocal (or inverse) of aa if a⋅b=1a \cdot b = 1. If such a bb exists, aa is invertible and we write b=a−1b = a^{-1}.

Division. For a,b∈Zna, b \in \mathbb{Z}_n with bb invertible, a/b=a⋅b−1a / b = a \cdot b^{-1}. The requirement "bb invertible" is the modular analog of "b≠0b \ne 0" on the reals — you cannot divide by something with no inverse. Why an inverse is needed: cancellation ab=ac⇒b=cab = ac \Rightarrow b = c is valid only when aa has an inverse. (Example in Z10\mathbb{Z}_{10}: 2⋅3=62\cdot 3 = 6 and 2⋅8=16≡62 \cdot 8 = 16 \equiv 6, so "6/26/2" is ambiguous — 22 has no inverse.)

Inverses in Z10\mathbb{Z}_{10}. From the multiplication table, the invertible elements are 1,3,7,91, 3, 7, 9:

Uniqueness of inverses. If aa has a reciprocal, it has exactly one. Proof: suppose bb and cc both satisfy ab=1ab = 1 and ca=1ca = 1. Then b=b⋅1=b(ac)=(ba)c=1⋅c=c,b = b\cdot 1 = b(ac) = (ba)c = 1\cdot c = c, so b=cb = c. (This is why a 11 appears at most once in any row or column of a multiplication table.) Taking the inverse twice returns the original: (a−1)−1=a(a^{-1})^{-1} = a.

Invertibility criterion (the key theorem). a∈Zna \in \mathbb{Z}_n is invertible if and only if gcd⁡(a,n)=1\gcd(a, n) = 1 (i.e. aa and nn are relatively prime).

This rests on Bézout's identity — the lecture's "second most important theorem of number theory": for integers a,ba, b there exist integers x,yx, y with ax+by=gcd⁡(a,b)ax + by = \gcd(a,b), and gcd⁡(a,b)\gcd(a,b) is the smallest positive value ax+byax+by can take. (The "most important" is the Division Algorithm: a=qb+ra = qb + r.)

Computing inverses with the extended Euclidean algorithm. To find a−1a^{-1} in Zn\mathbb{Z}_n: run Euclid's algorithm on nn and aa to confirm gcd⁡=1\gcd = 1, then back-substitute to write 1=xa+yn1 = xa + yn. Reducing mod nn gives a−1≡x(modn)a^{-1} \equiv x \pmod n (add a multiple of nn to land in Zn\mathbb{Z}_n).

Solving linear congruences.

Systems of congruences (Chinese Remainder Theorem). To solve x≡r1(modm1)x \equiv r_1 \pmod{m_1} and x≡r2(modm2)x \equiv r_2 \pmod{m_2}: substitute the general solution of the first (x=r1+m1kx = r_1 + m_1 k) into the second, solve the resulting congruence for kk using an inverse, then back-substitute. With coprime moduli the combined solution is unique mod m1m2m_1 m_2 — the final answer has the form x=x0+(m1m2) tx = x_0 + (m_1 m_2)\,t.

Factoring and the Fundamental Theorem of Arithmetic. Every positive integer nn factors into a unique product of primes, up to order. Examples: 30=2⋅3⋅530 = 2\cdot 3\cdot 5,   12=22⋅3\;12 = 2^2\cdot 3,   60=22⋅3⋅5\;60 = 2^2\cdot 3\cdot 5. The number 11 is the empty product of primes (its unique, prime-free factorization); 11 itself is not prime. Prime factorizations let you cancel cleanly, e.g. 6012=22⋅3⋅522⋅3=5\frac{60}{12} = \frac{2^2\cdot 3\cdot 5}{2^2\cdot 3} = 5.

Euclid's lemma. If pp is prime and p∣abp \mid ab, then p∣ap \mid a or p∣bp \mid b. (False for composite divisors: 20∣16⋅25=40020 \mid 16\cdot 25 = 400 but 20∤1620\nmid 16 and 20∤2520 \nmid 25.) Proof idea: if pp divides neither aa nor bb, then since pp's only divisors are 11 and pp, we get gcd⁡(p,a)=gcd⁡(p,b)=1\gcd(p,a) = \gcd(p,b) = 1. Bézout gives px+ay=1px + ay = 1 and pu+bw=1pu + bw = 1; multiplying these, every term on the right is divisible by pp (each contains a factor of pp or the factor abab, which pp divides), so p∣1p \mid 1 — impossible. Hence p∣ap \mid a or p∣bp \mid b.

Generalization to products of primes. If pp is prime and p∣q1q2⋯qnp \mid q_1 q_2 \cdots q_n where each qiq_i is prime, then p=qip = q_i for some ii. Proved by induction on nn: the base case p∣q1p \mid q_1 forces p=q1p = q_1 (both have only trivial divisors); the inductive step splits q1⋯qk+1q_1\cdots q_{k+1} via Euclid's lemma into p∣(q1⋯qk)p \mid (q_1\cdots q_k) — handled by the hypothesis — or p∣qk+1p \mid q_{k+1}, giving p=qk+1p = q_{k+1}.

Worked Example

Compute 1/291/29 in Z431\mathbb{Z}_{431} (i.e. find 29−129^{-1}), then use it to evaluate 30/2930/29.

First run the Euclidean algorithm on 431431 and 2929, recording remainders:

431=14⋅29+2529=1⋅25+425=6⋅4+1.\begin{aligned} 431 &= 14\cdot 29 + 25 \\ 29 &= 1\cdot 25 + 4 \\ 25 &= 6\cdot 4 + 1. \end{aligned}

The last nonzero remainder is 11, so gcd⁡(431,29)=1\gcd(431,29)=1 and 2929 is invertible. Back-substitute to write 11 as a combination of 431431 and 2929:

1=25−6⋅4=25−6 (29−25)=7⋅25−6⋅29=7 (431−14⋅29)−6⋅29=7⋅431−104⋅29.\begin{aligned} 1 &= 25 - 6\cdot 4 \\ &= 25 - 6\,(29 - 25) = 7\cdot 25 - 6\cdot 29 \\ &= 7\,(431 - 14\cdot 29) - 6\cdot 29 = 7\cdot 431 - 104\cdot 29. \end{aligned}

Reducing mod 431431 kills the 7⋅4317\cdot 431 term:

−104⋅29≡1(mod431)29−1≡−104≡−104+431=327(mod431).\begin{aligned} -104\cdot 29 &\equiv 1 \pmod{431} \\ 29^{-1} &\equiv -104 \equiv -104 + 431 = 327 \pmod{431}. \end{aligned}

So 1/29=3271/29 = 327. Now divide 3030 by 2929 using this inverse:

30/29=30⋅29−1=30⋅327=9810≡9810−22⋅431=328(mod431).\begin{aligned} 30 / 29 &= 30 \cdot 29^{-1} = 30 \cdot 327 \\ &= 9810 \equiv 9810 - 22\cdot 431 = 328 \pmod{431}. \end{aligned}

Therefore 30/29=32830/29 = 328 in Z431\mathbb{Z}_{431}.

Summary