The Timpson Lyceum · Discrete Math (2025)
Number Theory, GCD, and Modular Arithmetic - Lecture 19 (Discrete Math)
Overview
This lecture builds the core machinery of elementary number theory. Starting from the Division Algorithm (every pair of integers has a unique quotient and remainder), we define the greatest common divisor (GCD) and develop Euclid's algorithm, an astonishingly fast way to compute it — roughly 7,000 steps for numbers as large as , versus the hopeless task of testing every candidate divisor. We then prove that the GCD of and is the smallest positive value of , which leads to the Extended Euclidean algorithm for finding those coefficients and . Finally, we introduce modular arithmetic on the finite sets — clock-style addition, multiplication, and subtraction — and see why division is the one operation that resists an easy definition.
Key Concepts
Division Algorithm (recap). For any integers and (with ), there exist a unique quotient and remainder with The remainder must satisfy ; you can't say " goes into once remainder " — the correct statement is twice remainder .
Divisor and common divisor. If and , then is a common divisor of and . Example: are the positive common divisors of and .
Greatest common divisor. if is a common divisor of and and, for every other common divisor , we have . We treat as a function: .
The key fact behind Euclid's algorithm. Let (the remainder). Then Why it works: writing , any divisor of and also divides , and any divisor of and also divides . So and have exactly the same common divisors, hence the same GCD. (Formally: let , ; show and , so .)
Euclid's algorithm. Repeatedly replace with until the remainder is . The last nonzero remainder is the GCD. This terminates fast because (every integer divides ).
GCD as a smallest positive combination. For integers not both zero, the smallest positive value of over all integers is exactly . The set is a nonempty subset of (it contains ), so by the well-ordering principle it has a least element ; one shows , , and that any common divisor divides the combination , forcing .
Extended Euclidean algorithm. Runs Euclid's algorithm, then back-substitutes to express the GCD as . At each division step solve for the remainder, then work back up, eliminating remainders one at a time until the GCD is written in terms of the original and .
Relatively prime. Two integers are relatively prime when . They need not be prime themselves — e.g. . Consecutive integers are always relatively prime.
Corollary. and are relatively prime iff there exist integers with .
Modular arithmetic. Define (for ). Arithmetic "wraps around" like a clock that starts at : Both operations are closed on (the remainder is always in range), commutative, associative, with additive identity and multiplicative identity , and they distribute. ( under is a group.)
Congruence. means , which is equivalent to .
Modular subtraction. is the unique with ; it is computed as . For example in , (3 hours before 1 o'clock is 10 o'clock).
Why division is hard (preview). In , would need an with ; both and work (), so the answer isn't unique. A multiplicative inverse exists only when the numbers are relatively prime to — handled next time.
Worked Example
Extended Euclidean algorithm: find with .
Run Euclid's algorithm (left), recording each remainder (right):
Back-substitute, eliminating the remainder :
So , giving , .
Summary
- The Division Algorithm guarantees a unique quotient and remainder with ; this underpins everything that follows.
- , so Euclid's algorithm finds the GCD as the last nonzero remainder — exponentially faster than trial division.
- The GCD of and equals the smallest positive value of ; the Extended Euclidean algorithm recovers the coefficients by back-substitution.
- Two integers are relatively prime when their GCD is , equivalently when has an integer solution.
- with and is closed, commutative, associative, and has identities and .
- Modular subtraction is well-defined as ; modular division fails in general and works only when the divisor is relatively prime to .