Greatest Common Divisor and Least Common Multiple
Two whole numbers can share a surprising amount of hidden structure. The greatest common divisor (GCD) captures the largest chunk two numbers have in common, while the least common multiple (LCM) captures the smallest number they can both grow into. These twin ideas quietly power everything from reducing fractions and syncing calendars to the internals of modern cryptography. Better still, one of them — the GCD — can be found by an algorithm so elegant and so old that it has been in continuous use for more than two thousand years.
This page teaches you not just the recipes but why they work, so you can compute GCDs and LCMs quickly, check your answers, and understand the deep relationship that ties the two together.
Learning Objectives
- Define the GCD and LCM precisely and recognise them in fraction, scheduling, and factoring problems.
- Compute both using prime factorization.
- Compute the GCD using the Euclidean algorithm and explain why it always terminates.
- Use the identity to get one from the other.
- Recognise coprime (relatively prime) numbers and their special properties.
- Apply GCD and LCM to real problems: reducing fractions, adding fractions, and scheduling.
Quick Answer
The GCD of two integers is the largest positive integer that divides both of them; the LCM is the smallest positive integer that both of them divide. You can find either by prime factorization: for the GCD take each shared prime to its lowest power, and for the LCM take each prime to its highest power. For the GCD there is a much faster route, the Euclidean algorithm: repeatedly replace the larger number by its remainder on division by the smaller, until the remainder is zero — the last nonzero remainder is the GCD. The two quantities are locked together by the beautiful identity , so once you have one you get the other instantly.
Where It Came From
The need for the GCD is as old as the need to compare quantities. The ancient Greeks did not think in terms of numbers alone; they thought geometrically, in terms of lengths. A central question was whether two lengths were commensurable — that is, whether some common unit could measure both an exact whole number of times. Finding the greatest such common measure is exactly the problem of finding the GCD.
The method for doing this appears in Euclid's Elements (around 300 BCE), Book VII, Propositions 1 and 2, as the procedure of antanairesis — "repeated subtraction." To find the greatest common measure of two lengths, you repeatedly subtract the smaller from the larger; when the two become equal, that value is the greatest common measure. This is the Euclidean algorithm, and it is often cited as the oldest nontrivial algorithm still in everyday use. It almost certainly predates Euclid, who was compiling and systematising earlier knowledge rather than inventing it from scratch.
The genius of the method is what it avoids. There is no need to factor the numbers, which for large numbers is extremely hard. By trading the large problem for a smaller one at every step — replacing a pair by a strictly smaller pair — the algorithm grinds relentlessly down to the answer. Centuries later this same "reduce to a smaller instance" idea became a cornerstone of computer science, and the Euclidean algorithm is still taught as the archetype of a recursive procedure. It also generalises: the extended Euclidean algorithm, which tracks the arithmetic along the way, is the workhorse behind modular inverses in RSA encryption and countless other cryptographic systems.
Divisors, Multiples, and the Two Definitions
Before computing anything, get the two definitions crisp, because students constantly swap them.
A divisor (or factor) of is a number that divides with no remainder. A multiple of is a number you get by multiplying by an integer.
- The greatest common divisor is the largest number that is a divisor of both and . Divisors are bounded above by the number itself, so a greatest one exists.
- The least common multiple is the smallest positive number that is a multiple of both and . Multiples go up forever, so we want the least one.
Worked example. Take and .
Divisors of : . Divisors of : . The common divisors are , and the greatest is . So .
Multiples of : Multiples of : The first value appearing in both lists is . So .
Listing works for small numbers but collapses for large ones — hence the methods below.
Method 1: Prime Factorization
Every integer greater than factors uniquely into primes (the Fundamental Theorem of Arithmetic). That uniqueness is what makes this method reliable.
The rule:
- For the GCD, take every prime that appears in both factorizations, raised to the lowest power it has in either.
- For the LCM, take every prime that appears in either factorization, raised to the highest power it has in either.
Worked example. Find and .
Factor each:
Line up the primes :
| Prime | Power in 180 | Power in 168 | Min (GCD) | Max (LCM) |
|---|---|---|---|---|
| 2 | 2 | 3 | 2 | 3 |
| 3 | 2 | 1 | 1 | 2 |
| 5 | 1 | 0 | 0 | 1 |
| 7 | 0 | 1 | 0 | 1 |
GCD .
LCM .
Check with the product identity: , and . They match.
Why does taking the minimum give the GCD? A number divides both and exactly when its prime powers do not exceed either number's prime powers — so each prime is capped at the smaller exponent. The largest such number uses those caps exactly. The maximum rule for the LCM is the mirror image.
Method 2: The Euclidean Algorithm
Factoring large numbers is slow. The Euclidean algorithm sidesteps it entirely, using only division with remainder.
The key fact: , where is the remainder when is divided by . Intuitively, any number dividing both and must also divide (and hence the remainder ), so the pair and the pair share exactly the same common divisors — and therefore the same greatest one.
The procedure. Divide, take the remainder, repeat with the divisor and remainder, until the remainder is . The last nonzero remainder is the GCD.
Worked example. Find .
The last nonzero remainder is , so .
Notice how fast this is — three divisions, no factoring. If you tried to factor and by hand, the algorithm would still beat you, and the gap only widens for genuinely large numbers.
Why it always stops: each remainder is strictly smaller than the previous divisor and can never go below . A strictly decreasing sequence of non-negative integers cannot go on forever, so a remainder of is guaranteed.
The Relationship Between GCD and LCM
The single most useful fact linking the two is:
This lets you compute the LCM the smart way: find the GCD (fast, via Euclid), then divide.
Worked example. Find . We already found .
To avoid huge intermediate numbers, divide first: , then . Same answer, easier arithmetic.
Why does the identity hold? For each prime, — the smaller and larger exponents always add up to the sum of the two exponents. Summing this over all primes says the exponents in match the exponents in prime by prime, so the two products are equal.
When the numbers are called coprime (or relatively prime), and the identity collapses to . For example, and are coprime, so .
Real-World Applications
- Reducing fractions. To write in lowest terms, divide top and bottom by : . One GCD does the whole job.
- Adding fractions. The least common denominator is the LCM of the denominators. For , , giving .
- Scheduling and cycles. Two buses leave a depot every and minutes. They next leave together after minutes. Gears, traffic lights, and planetary alignments follow the same LCM logic.
- Cryptography. The extended Euclidean algorithm computes modular inverses, a core step in RSA key generation. The plain Euclidean algorithm's speed is exactly why it scales to the huge numbers used in encryption.
- Tiling and packing. The largest square tile that exactly fills a cm floor has side cm.
Common Mistakes
Mistake 1: Swapping min and max. Students take the highest powers for the GCD. This gives the LCM instead. Why it's wrong: a common divisor cannot have more of a prime than the poorer of the two numbers has. Correction: GCD uses the minimum exponent (the "greatest common divisor" is at most as big as either number); LCM uses the maximum.
Mistake 2: Forgetting primes that appear in only one number when computing the LCM. For , dropping the or the gives a number that isn't actually a multiple of both. Why it's wrong: the LCM must be divisible by each original number in full. Correction: include every prime from either factorization for the LCM. (For the GCD, by contrast, a prime in only one number contributes nothing.)
Mistake 3: Stopping the Euclidean algorithm too early or reading the wrong number. Some take the last quotient or the final remainder as the answer. Why it's wrong: the quotients are irrelevant to the GCD, and is never the answer. Correction: the GCD is the last nonzero remainder — the divisor in the step that produced remainder .
Comparison and Connections
| Feature | GCD | LCM |
|---|---|---|
| What it finds | Largest shared divisor | Smallest shared multiple |
| Prime-power rule | Minimum exponent | Maximum exponent |
| Size relative to inputs | both numbers | both numbers |
| Fast algorithm | Euclidean algorithm | Via GCD, then divide |
| When numbers are coprime | Equals | Equals |
The GCD and LCM are dual notions — one reaches down to what two numbers share, the other reaches up to what contains them both. Both rest on the Fundamental Theorem of Arithmetic (unique prime factorization), which is why the prime-power rules are trustworthy. The Euclidean algorithm connects forward to modular arithmetic and its extended form to Bézout's identity, for some integers .
Practice Questions
Recall
State the definition of the GCD and of the LCM in one sentence each.
Answer: The GCD of two integers is the largest positive integer that divides both; the LCM is the smallest positive integer that is a multiple of both.
Understanding
Using prime factorization, find and .
Answer: , . GCD . LCM . Check: . Correct.
Application
Use the Euclidean algorithm to find , then find .
Answer: ; ; . So . Then .
Analysis
Explain why must hold, referring to prime exponents. Then show why it can fail if extended naively to three numbers.
Answer: For each prime, , so multiplying GCD and LCM recovers exactly the exponents of . For three numbers the identity fails because and of three exponents need not sum to the total; e.g. for , but .
FAQ
Is the GCD ever bigger than the numbers involved? No. A divisor of can be at most , so is at most the smaller of and . The LCM, conversely, is at least the larger of the two.
What is ? It is (for ), because every integer divides , so the largest divisor of both and is just the largest divisor of , namely . This is exactly the terminating case of the Euclidean algorithm.
Do GCD and LCM work for more than two numbers? Yes. Extend the prime-power rules to all the numbers (min across all for GCD, max across all for LCM), or apply the Euclidean algorithm pairwise: .
Why is it called "Euclidean" if Euclid may not have invented it? Because its first surviving written statement is in Euclid's Elements. The naming honours the source we can point to, a common convention in the history of mathematics.
What does "coprime" mean and why does it matter? Two numbers are coprime when — they share no prime factors. It matters because their LCM is simply their product, and coprimality is the condition that makes fractions already reduced and makes modular inverses exist.
Quick Revision
- GCD = largest common divisor; LCM = smallest common multiple.
- Factorization: GCD takes the minimum prime exponents; LCM takes the maximum.
- Euclidean algorithm: replace with until remainder ; GCD is the last nonzero remainder.
- Master identity: , so .
- Coprime means , and then .
- GCD smaller number; LCM larger number.
Related Topics
Prerequisites
Related Topics
- Fundamental Theorem of Arithmetic
- Modular Arithmetic