Greatest Common Divisors
Learning objectives
- Define the greatest common divisor of two integers
- Apply the Euclidean algorithm to compute
- Express the GCD as a linear combination via Bezout coefficients
- Recognise when two integers are relatively prime
Why does a tiny rule from antiquity power the modern internet? Every time your browser shakes hands with a banking site, every time a credit card terminal signs a transaction, every time a Signal message lands on your phone, an algorithm credited to Euclid is running in the background. The greatest common divisor is the largest integer that divides two numbers cleanly, and the Euclidean algorithm for finding it is the oldest non-trivial algorithm still in everyday use. It is fast (logarithmic in the inputs), it is exact, and it is the gateway to Bezout coefficients, modular inverses, RSA key generation, and a dozen other corners of cryptography. Master this one tool and the rest of Chapter 7 falls into place.
The definition, sharpened
For integers and not both zero, is the unique positive integer satisfying two conditions: (1) and , and (2) every common divisor of and also divides . The second condition is stronger than “” — it says is the maximum common divisor in the divisibility order, not merely in size. Two integers with are called coprime (equivalently, relatively prime).
The Euclidean algorithm
The heart of the algorithm is a one-line observation. If with , then any common divisor of and also divides , and vice versa. Therefore . Iterate this rewriting and the remainders form a strictly decreasing sequence of non-negative integers, so the process must terminate. The last non-zero remainder is the GCD.
Worked example. : , , . The last non-zero remainder is , so .
Bezout’s identity
For any integers not both zero, there exist integers with . The integers are the Bezout coefficients and are not unique — they are recovered by reading the Euclidean algorithm backwards. Back-substituting in the example above: . So . Bezout’s identity is the bridge from the GCD to modular inverses: when , the coefficient in is exactly .
(The stepper above visualises an iterative algorithm. Use it as a mental model for stepping through the Euclidean algorithm: each step shrinks the pair until the second entry reaches zero.)
Pause and think: Before reading on, predict . (Hint: every integer divides , so the question reduces to: what is the largest divisor of ?) Then predict . The pattern that emerges is worth a sentence of explanation in your own words.
Try it
- Predict first: how many division steps does the Euclidean algorithm take on ? (Both are Fibonacci numbers — this is the slowest case for inputs of that size.) Then run it and count.
- Compute by hand. Find Bezout coefficients such that .
- Prove without a calculator: for any positive integer , . Use the “subtract one multiple” trick that drives the algorithm.
- Two-step puzzle: compute . The answer has a clean closed form — can you guess in general?
A trap to watch for
The GCD and the least common multiple (LCM) are siblings, not synonyms. is the largest integer dividing both; is the smallest positive integer divisible by both. They satisfy , so once you know one you can recover the other — but they are not the same number. A frequent student error is to compute and report as “the common multiple,” or to call “the largest common factor.” If you find yourself unsure which one a problem wants, ask: am I being asked for the biggest divisor (GCD, sits below both) or the smallest multiple (LCM, sits above both)?
What you now know
You can compute in logarithmic time, recover Bezout coefficients by back-substitution, and translate “coprime” into the equation . In the next section, prime factorisation, Bezout’s identity is the key lemma that proves uniqueness: it is precisely why a prime dividing a product must divide one of the factors, and therefore why every integer has only one factorisation into primes.
References
- Velleman, D. J. (2019). How to Prove It: A Structured Approach (3rd ed.). Cambridge University Press, §7.1.
- Hardy, G. H., Wright, E. M. (2008). An Introduction to the Theory of Numbers (6th ed.). Oxford University Press, ch. 2.
- Niven, I., Zuckerman, H. S., Montgomery, H. L. (1991). An Introduction to the Theory of Numbers (5th ed.). Wiley, ch. 1.
- Rosen, K. H. (2010). Elementary Number Theory (6th ed.). Pearson, ch. 3.
- Knuth, D. E. (1997). The Art of Computer Programming, Vol. 2: Seminumerical Algorithms (3rd ed.). Addison-Wesley, §4.5.2.