Divisibility and the Euclidean Algorithm
Divisibility and the Euclidean Algorithm
Section titled “Divisibility and the Euclidean Algorithm”0. Why This Page Exists
Section titled “0. Why This Page Exists”Every HTTPS connection you make begins with a division step. When your browser verifies a certificate, it computes for 600-digit numbers using the same algorithm Euclid wrote down around 300 BCE. When a computer algebra system simplifies a fraction, it uses the same algorithm. When a number theorist proves that is irrational, the proof goes through the same lemma.
The reason this one idea recurs across 2,300 years of mathematics, from geometry to public-key cryptography, is that the Euclidean algorithm is not just a method for computing a greatest common divisor. It is the theorem that reveals the structure of the integers: that every ideal is principal, that primes are irreducible, that unique factorisation holds. These are not obvious properties of ; they fail in other rings; and the proof that they hold goes through Bézout’s identity, which goes through the Euclidean algorithm.
This page builds that chain from the ground up, the way Aluffi builds ring theory: by constructing the tools you’ll need later and understanding why they work, not just verifying that they do.
0.1 The Problem That Starts Everything
Section titled “0.1 The Problem That Starts Everything”Here is a concrete question that has nothing to do with number theory at first glance.
You have two audio files of lengths 252 and 198 seconds. You want to cut both into identical segments of maximum length so that nothing is wasted. How long should each segment be?
If you think about this for a moment, you realise you need the largest integer that divides both 252 and 198. That is . But how do you find it? You could try every integer from 198 down to 1; but for 600-digit numbers, that’s not just slow, it’s longer than the age of the universe.
The answer; the idea that makes the computation feasible; is the Euclidean algorithm. And the reason the Euclidean algorithm works is a property of the integers that most people never think to question: the division algorithm. This page builds from the division algorithm to Bézout’s identity to the extended Euclidean algorithm, and each step earns the next.
Exercise 0.1. Before reading further, try to find by listing all divisors of each number. Then notice how much faster the method on this page will be.
0.2 Why Divisibility Is Not Obvious
Section titled “0.2 Why Divisibility Is Not Obvious”The integers are the first number system where a question like “does divide ?” is interesting. In or , every nonzero number divides every other number (), so divisibility is trivial. The integers are special because division is restricted: the quotient must also be an integer.
This restriction is what creates structure; and what makes number theory rich.
Definition. For integers and with , we say divides , written , if there exists an integer such that .
Exercise 0.2. Show that for every , and that only for .
The definition is simple, but the consequences are not. The most important one:
Proposition (Linearity of Divisibility). If and , then for all integers .
Proof. and for some integers . Then , so divides the result.
This “linearity” is what makes divisibility proofs work: to show , show divides each term separately.
Exercise 0.3. Show that if and , then . Hint: add and subtract .
This exercise is not busywork; the result is exactly what makes modular arithmetic well-defined, and it is the proof you’ll need in Congruences.
0.3 The Division Algorithm: More Than Long Division
Section titled “0.3 The Division Algorithm: More Than Long Division”Every schoolchild knows how to divide 252 by 198: the quotient is 1 and the remainder is 54. What most never question is that the answer is unique; that you couldn’t also get quotient 2 with remainder −144. The uniqueness is what makes the algorithm deterministic and the concept of “remainder” well-defined.
Theorem (Division Algorithm). For integers and with , there exist unique integers (quotient) and (remainder) such that
Proof of existence. The set is non-empty (take sufficiently negative) and bounded above by . Let be its supremum, which is an integer by the Archimedean property. Set . If , then , contradicting the maximality of .
Proof of uniqueness. Suppose with both remainders in . Then . Since , we need and .
The uniqueness proof is worth understanding deeply. It works because the interval is strictly smaller than the spacing between consecutive multiples of . If you widened the interval to , two quotients could work. This is not pedantry; in (Gaussian integers), the “remainder” is measured by a norm, and the norm function does not always decrease the way ‘s does. When it does decrease, the ring has unique factorisation (like ); when it doesn’t, it doesn’t (like ). The division algorithm is not just a computational tool; it is the property that makes the entire edifice of arithmetic stand.
Exercise 0.4. Prove the division algorithm for by reducing to the case . What changes in the inequality ?
Exercise 0.5. Show that for any integer , is divisible by 3. Hint: ; but you can also prove it by factoring and checking two consecutive integers.
0.4 The Greatest Common Divisor: Definition and Existence
Section titled “0.4 The Greatest Common Divisor: Definition and Existence”Definition. For integers not both zero, is the largest positive integer dividing both.
Why this definition works. You might worry: how do we know there’s a largest common divisor? The set of common divisors is finite (all bounded by ), so a maximum exists by the well-ordering of . This is one of those cases where the structure of (every non-empty subset has a least element) does the heavy lifting.
Theorem (Bézout’s Identity). is the smallest positive integer in the set
In particular, there exist integers with .
This is the first genuinely structural theorem in number theory, and the proof technique (well-ordering of a non-empty set of positive integers) is the single most important proof method in the subject. Let’s look at it carefully.
Proof. is non-empty (if , take , ). By the well-ordering principle, has a least element . We show in two steps.
Step 1: and . Divide by : with . Then
But contradicts the minimality of unless . So . Similarly .
Step 2: is the greatest common divisor. If and , then (because is a linear combination). So .
Why this proof matters. Look at Step 1 again. The key move is that the remainder is itself an element of ; because is closed under subtraction of elements of the form . This is exactly the argument that shows every ideal of is principal, and it is the proof template for Bézout domains in ring theory. The Euclidean algorithm doesn’t just compute a gcd; it proves a structural theorem about the integers.
Exercise 0.6. Find and Bézout coefficients. Then find all solutions to . Answer: ; ; all solutions are , .
Exercise 0.7. Show that . Why this matters: this is the mathematical basis of the subtraction-based Euclidean algorithm that Euclid actually wrote down (Elements, Book VII, Propositions 1–2).
A consequence you’ll need later. (coprimality) is equivalent to the existence of with . This is the definition of a unimodular row, and it is the reason modular inverses exist (when , the inverse of mod is the Bézout coefficient ). See Congruences.
Euclid’s lemma falls out immediately: if and , write , multiply by : . Since and (because ), we get . This is the key step in proving unique factorisation; and it fails in precisely because Bézout fails there, which is why unique factorisation fails there.
0.5 The Euclidean Algorithm
Section titled “0.5 The Euclidean Algorithm”The division algorithm says: . The crucial observation is that
Why? Any common divisor of and divides (by linearity of divisibility). Any common divisor of and divides (same reason). So the two pairs have exactly the same set of common divisors, hence the same greatest common divisor.
This means we can replace the pair by the smaller pair with the same gcd - and iterate:
The remainders satisfy , so the sequence must terminate. When it terminates, the last non-zero remainder is .
Worked example. :
| Step | Equation | Observation |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 |
Answer: .
0.6 The Extended Euclidean Algorithm
Section titled “0.6 The Extended Euclidean Algorithm”Back-substitute through the table to express the gcd as a linear combination:
So : Bézout coefficients , .
This back-substitution is mechanical and tedious. The extended Euclidean algorithm automates it by maintaining the coefficients alongside the remainders; and this is what you actually implement when computing modular inverses for RSA decryption.
The connection to cryptography. To find the decryption exponent in RSA, you compute the inverse of modulo ; which is exactly the extended Euclidean algorithm applied to . The 2,300-year-old algorithm is running in every TLS handshake.
0.7 What Can Go Wrong
Section titled “0.7 What Can Go Wrong”| Pitfall | Why it happens | Fix |
|---|---|---|
| Negative remainder from division algorithm | Adjusting the wrong way for negative | Use |
| No largest common divisor exists | Define by convention, or don’t call the function | |
| Bézout coefficients not unique | also works for all | Report one pair; the exam wants a pair |
| Cancelling from | Only cancel when is invertible mod |
0.8 Summary: The Chain of Reasoning
Section titled “0.8 Summary: The Chain of Reasoning”Each step uses the previous one. The division algorithm is the foundation; unique factorisation is the skyscraper. The next page builds the tower.
See Also
Section titled “See Also”- Congruences; the division algorithm gives you residue classes; the next page builds arithmetic on them
- Primes and the FTA - Euclid’s lemma is the key to unique factorisation
- Number Theory and Cryptography; where the extended Euclidean algorithm meets RSA key generation