The greatest common divisor of two numbers can be read off their prime factorizations: it is the product of the primes they have in common, each taken as many times as it occurs in both. This lesson proves that rule, shows that every common divisor divides the gcd, and settles when two divisibility tests can be combined.
The common primes
The lesson “The greatest common divisor” found gcd(a, b) by listing divisors. Prime factorizations give another way.[1] The lesson “Prime factorization is unique” proved that d divides n exactly when every prime occurs in d at most as many times as in n. A common divisor of a and b must satisfy this for both numbers at once.
Let a and b be whole numbers, both at least 1. Take the primes that occur in the prime factorizations of both a and b, each as many times as it occurs in the factorization where it occurs fewer times. Their product (1 if there is no common prime) is gcd(a, b). Moreover, every common divisor of a and b divides gcd(a, b).
Call the list of primes described in the Theorem the common part, and its product g. (For a = 1 or b = 1 the common part is empty and g = 1.)
g is a common divisor: every prime of the common part occurs in it at most as many times as in a, so g | a by the Theorem on divisors of the lesson “Prime factorization is unique” (or g = 1, which divides everything); in the same way g | b.
Now let d be any common divisor of a and b. By the same Theorem, each prime occurs in d at most as many times as in a, and at most as many times as in b: at most the smaller of the two counts, which is its count in the common part. If d = 1, then d | g. If d ≥ 2, then g ≥ 2 too (the primes of d are in the common part), and by the Theorem on divisors once more, d | g. In both cases d | g, so d ≤ g (lesson “Divisibility”, the Proposition on size). Hence g is the greatest common divisor.
The rule is standard: the gcd takes each common prime the smaller of the two numbers of times it occurs (in the books’ notation, with the smaller of its two exponents).[2]
The method in columns
In practice, write the two factorizations with equal primes in the same column,[7] mark the columns that contain a prime in both rows, bring those primes down and multiply them.[8]
Find gcd(84, 120) from the prime factorizations.
- 84 = 2 × 42 = 2 × 2 × 21 = 2 × 2 × 3 × 7. 120 = 2 × 60 = 2 × 2 × 30 = 2 × 2 × 2 × 15 = 2 × 2 × 2 × 3 × 5.
- 2 occurs twice in 84 and three times in 120: take it twice. 3 occurs once in each: take it once. 5 and 7 occur in only one number.
- gcd(84, 120) = 2 × 2 × 3 = 12.
Answer: 12. Check: 84 = 12 × 7 and 120 = 12 × 10, and 7 and 10 have no prime in common.
Find gcd(1,260, 1,386).
- 1,260 = 2 × 2 × 3 × 3 × 5 × 7 (lesson “Prime factorization”).
- 1,386 = 2 × 693 = 2 × 3 × 231 = 2 × 3 × 3 × 77 = 2 × 3 × 3 × 7 × 11.
- Common primes: 2 (once in 1,386), 3 (twice in each), 7 (once in each). 5 and 11 are not common.
- gcd = 2 × 3 × 3 × 7 = 126.
Answer: gcd(1,260, 1,386) = 126. Check: 1,260 = 126 × 10 and 1,386 = 126 × 11; 10 and 11 are consecutive, so relatively prime.
Find gcd(35, 66) and gcd(13, 52).
- 35 = 5 × 7 and 66 = 2 × 3 × 11 have no prime in common. The common part is empty, so gcd(35, 66) = 1.
- 13 is prime and 52 = 2 × 2 × 13. The common part is 13, so gcd(13, 52) = 13.
Answer: 1 and 13. The first pair is relatively prime; in the second, 13 | 52, as in the lesson “The greatest common divisor”.
72 = 2 × 2 × 2 × 3 × 3 and 108 = 2 × 2 × 3 × 3 × 3. One person says gcd(72, 108) = 2 × 3 = 6; another says 2 × 2 × 2 × 3 × 3 × 3 = 216. Who is right?
- Taking each common prime once misses copies that both numbers have: 2 × 2 divides both, and so does 3 × 3. 6 is a common divisor, but not the greatest.
- Taking the larger count gives 216, which is more than 72 and so cannot divide 72. 216 is in fact a common multiple.
- The right count is the smaller one: 2 twice (72 has three, 108 two) and 3 twice (72 has two, 108 three).
Answer: neither; gcd(72, 108) = 2 × 2 × 3 × 3 = 36, as found by listing divisors in the previous lesson.
Pair the common primes
- Round
- 1
- Score
- 0
- Streak
- 0
Find gcd(77, 42). Pair each prime of 77 with an equal prime of 42: tap one, then the other. Make every pair you can, then check.
Paired: nothing yet (a product of no primes is 1)
Relatively prime numbers and combined tests
Two whole numbers a, b ≥ 1 are relatively prime exactly when no prime occurs in both of their prime factorizations.
By the Theorem, gcd(a, b) is the product of the common part; it is 1 exactly when the common part is empty.
The lesson “Divisibility rules and why they work” combined the tests for 2 and 3 into a test for 6 and warned that two tests cannot always be combined. Burton states the condition and gives the warning example: 6 | 24 and 8 | 24, but 6 × 8 ∤ 24, because 6 and 8 are not relatively prime.[9]
Let a and b be relatively prime. If a | N and b | N, then a × b | N.
If N = 0, then a × b | 0. If N = 1, then a = b = 1 and a × b = 1 | 1. Let N ≥ 2, so a, b ≥ 1. Writing the factorizations of a and b side by side gives a product of primes equal to a × b, so by uniqueness it is the factorization of a × b (if a × b > 1). Take any prime p. Since a and b have no prime in common, p occurs in at most one of them, and its count in a × b is its count in a or its count in b (or 0). Either count is at most its count in N, because a | N and b | N. So every prime occurs in a × b at most as often as in N, and a × b | N by the Theorem on divisors.
(a) Does 12 divide 7,548? (b) 4 | 36 and 6 | 36. Does 24 | 36?
- (a) 12 = 4 × 3, and 4 = 2 × 2 and 3 have no common prime. 4 | 7,548, since its last two digits form 48 = 12 × 4. 3 | 7,548, since its digit sum is 7 + 5 + 4 + 8 = 24 = 8 × 3. By the Corollary, 12 | 7,548.
- (b) 24 = 4 × 6, but gcd(4, 6) = 2: both contain the prime 2. The Corollary does not apply, and indeed 24 ∤ 36 (36 = 1 × 24 + 12).
Answer: (a) yes, 7,548 = 629 × 12; check: 629 × 12 = 6,290 + 1,258 = 7,548. (b) No: the two tests share the prime 2 and cannot be combined.
More than two numbers
The gcd of three numbers a, b, c, not all 0, is the largest number that divides all three.[10] The same proof shows that, for numbers at least 1, it is the product of the primes common to all three factorizations, each taken the smallest number of times it occurs.
Find gcd(60, 84, 126). Are any two of the numbers relatively prime?
- 60 = 2 × 2 × 3 × 5, 84 = 2 × 2 × 3 × 7, 126 = 2 × 3 × 3 × 7.
- 2 occurs in all three, at least once: take it once. 3 occurs in all three, at least once: take it once. 5 and 7 are not in all three.
- gcd(60, 84, 126) = 2 × 3 = 6.
- Pairs: 60 and 84 share 2, 2, 3; 60 and 126 share 2, 3; 84 and 126 share 2, 3, 7. No pair is relatively prime.
Answer: 6. Check: 60 = 6 × 10, 84 = 6 × 14, 126 = 6 × 21.
Three numbers can have gcd 1 without any two of them being relatively prime: 6, 10 and 15 have no prime common to all three, but each pair shares one (2, 3 or 5).[11] Numbers of which every two are relatively prime are called pairwise relatively prime.[12]
With exponents, the rule reads: each prime is taken with the smaller of its two exponents, a prime missing from a number having exponent 0.[13] Exponents are taught in the unit Powers & Square Roots. For large numbers, finding the factorizations is slow, so the gcd is better found without them,[14] by the method of the next lesson, “The Euclidean algorithm”. The common multiples of two numbers, read from the factorizations with the larger counts, are the subject of the lesson “The least common multiple”.
Exercises
Find gcd(90, 150) from the prime factorizations.
▸ Show solution
90 = 2 × 3 × 3 × 5 and 150 = 2 × 3 × 5 × 5. Common part: 2, 3, 5 (3 is twice in 90 but once in 150; 5 once in 90). gcd = 2 × 3 × 5 = 30. Check: 90 = 30 × 3, 150 = 30 × 5.
Without multiplying out, find the gcd of 2 × 2 × 3 × 7 × 7 and 2 × 3 × 3 × 5 × 7.
▸ Show solution
Common part: 2 (once in the second), 3 (once in the first), 7 (once in the second): gcd = 2 × 3 × 7 = 42. The numbers are 588 and 630; check: 588 = 42 × 14, 630 = 42 × 15.
Are 527 and 589 relatively prime?
▸ Show solution
A prime common to both numbers divides their difference, 589 − 527 = 62 = 2 × 31 (rule on differences). 2 does not divide 527 (it is odd), but 31 does: 527 = 17 × 31 and 589 = 19 × 31. So the factorizations are 17 × 31 and 19 × 31, the prime 31 is common, and gcd(527, 589) = 31: they are not relatively prime.
Prove that 15 | N exactly when 3 | N and 5 | N, and test 4,635.
▸ Show solution
15 = 3 × 5, and 3 and 5 are relatively prime. If 3 | N and 5 | N, the Corollary gives 15 | N; conversely, 15 | N gives 3 | N and 5 | N by the rule on chains. For 4,635: the digit sum is 18 = 6 × 3, and the last digit is 5. So 15 | 4,635; indeed 4,635 = 309 × 15.
Let a, b, k ≥ 1. Prove that gcd(k × a, k × b) = k × gcd(a, b).
▸ Show solution
Write a, b and k ≥ 1 as products of primes. The factorization of k × a is that of k together with that of a, so each prime occurs in k × a as often as in k plus as often as in a; the same for k × b. For each prime, the smaller of (count in k + count in a) and (count in k + count in b) is the count in k plus the smaller of the counts in a and b. So the common part of k × a and k × b is the factorization of k together with the common part of a and b, and gcd(k × a, k × b) = k × gcd(a, b).
This is a standard theorem.[15] Example: gcd(60, 90) = 30 × gcd(2, 3) = 30.
Let a ≥ 1, b and c be whole numbers with a | b × c and gcd(a, b) = 1. Prove that a | c.
▸ Show solution
If a = 1 there is nothing to prove. Otherwise let p be a prime of a, occurring k times in a. Since gcd(a, b) = 1, p does not occur in b, so it occurs in b × c exactly as often as in c. Since a | b × c, it occurs in b × c at least k times. So p occurs in c at least k times. This holds for every prime of a, so a | c by the Theorem on divisors (if c = 0, a | c anyway).
This is the general form that Burton calls Euclid’s lemma.[16] Example: 9 | 4 × 63 = 252 and gcd(9, 4) = 1, so 9 | 63.
Summary
- gcd(a, b) is the product of the primes common to both factorizations, each taken the smaller number of times it occurs; with no common prime it is 1.
- Every common divisor of a and b divides gcd(a, b).
- a and b are relatively prime exactly when their factorizations share no prime.
- If a and b are relatively prime and both divide N, then a × b divides N; tests for divisors that share a prime cannot be combined this way.
- For three numbers, take the primes common to all three; three numbers can have gcd 1 without being pairwise relatively prime (6, 10, 15).
Sources
- 1.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.3, “Primes and Greatest Common Divisors” (4.3.6, “Greatest Common Divisors and Least Common Multiples”), p. 281 (the whole topic: pp. 281–282).
“Another way to find the greatest common divisor of two positive integers is to use the prime factorizations of these integers.”
Used for: the gcd can be found from the prime factorizations. - 2.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 3, “Primes and Their Distribution”, section 3.1, “The Fundamental Theorem of Arithmetic”, p. 42 (the whole topic: pp. 42).
“Prime factorizations provide another means of calculating greatest common divisors.”
Used for: the gcd is calculated from the prime factorizations, each prime taken with the smaller exponent (Burton writes ri = min(ki, ji), the smaller of the two exponents). - 3.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 3, “Primes and Their Distribution”, section 3.1, “The Fundamental Theorem of Arithmetic”, p. 42 (the whole topic: pp. 42).
“the smaller of the two exponents associated with pi in the two representations”
Used for: each common prime is taken the smaller number of times. - 4.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.3, “Primes and Greatest Common Divisors” (4.3.6, “Greatest Common Divisors and Least Common Multiples”), p. 281 (the whole topic: pp. 281–282).
“Further, no larger integer can divide both a and b, because the exponents of the primes in this factorization cannot be increased, and no other primes can be included.”
Used for: the proof: the product of the common part divides both numbers, and no larger number does, since no prime can be taken more often and no other prime included. - 5.Euclid, trans. T. L. Heath, ed. D. E. Joyce, “Euclid’s Elements, Book VII”, Clark University.Section “Propositions”. mathcs.clarku.edu/~djoyce/java/elements/bookVII/bookVII.html · open at the quoted passage.
“If a number measures two numbers, then it also measures their greatest common measure.”
Used for: every common divisor divides the gcd (Euclid, Elements VII.2, Corollary). - 6.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.3, “The Greatest Common Divisor”, before Theorem 2.6, p. 24 (the whole topic: pp. 24).
“The subsequent theorem often serves as a definition of gcd(a, b). The advantage of using it as a definition is that order relationship is not involved.”
Used for: the property that every common divisor divides the gcd often serves as its definition, since it does not compare sizes. - 7.Lynn Marecek, MaryAnne Anthony-Smith and Andrea Honeycutt Mathis, Prealgebra (2nd ed., OpenStax, Rice University, 2020).Chapter 10, “Polynomials”, section 10.6, “Introduction to Factoring Polynomials” (“Find the Greatest Common Factor of Two or More Expressions”), Example 10.80, p. 846 (the whole topic: pp. 846–847).
“Step 2: List all factors--matching common factors in a column.”
Used for: the method: write the factorizations with equal primes in the same column. - 8.Lynn Marecek, MaryAnne Anthony-Smith and Andrea Honeycutt Mathis, Prealgebra (2nd ed., OpenStax, Rice University, 2020).Chapter 10, “Polynomials”, section 10.6, “Introduction to Factoring Polynomials” (“Find the Greatest Common Factor of Two or More Expressions”), Example 10.80, p. 847 (the whole topic: pp. 846–847).
“In each column, circle the common factors. Circle the 2, 2, and 3 that are shared by both numbers. Step 3: Bring down the common factors that all expressions share. Bring down the 2, 2, 3 and then multiply. Step 4: Multiply the factors.”
Used for: mark the columns with a common prime, bring those primes down and multiply them. - 9.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.3, “The Greatest Common Divisor”, Corollary 2 to Theorem 2.4, p. 23 (the whole topic: pp. 22–23).
“If 6 and 8 were relatively prime, of course, this situation would not arise. This brings us to Corollary 2. Corollary 2. If a | c and b | c, with gcd(a, b) = 1, then ab | c.”
Used for: if a | c and b | c with a and b relatively prime, then a × b | c; the warning example 6 | 24 and 8 | 24 but 6 × 8 ∤ 24. - 10.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.4, “The Euclidean Algorithm”, p. 30 (the whole topic: pp. 30–31).
“In the case of three integers, a, b, c, not all zero, gcd(a, b, c) is defined to be the positive integer d having the following properties”
Used for: the gcd of three numbers, not all 0: the largest number dividing all three. - 11.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.4, “The Euclidean Algorithm”, p. 31 (the whole topic: pp. 30–31).
“The reader is cautioned that it is possible for three integers to be relatively prime as a triple (in other words, gcd(a, b, c) = 1), yet not relatively prime in pairs; this is brought out by the integers 6, 10, and 15.”
Used for: three numbers can have gcd 1 without any two being relatively prime, as 6, 10 and 15 show. - 12.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.3, “Primes and Greatest Common Divisors” (4.3.6, “Greatest Common Divisors and Least Common Multiples”), Definition 4, p. 281 (the whole topic: pp. 281).
“The integers a1, a2, … , an are pairwise relatively prime if gcd(ai, aj) = 1 whenever 1 ≤ i < j ≤ n.”
Used for: the term pairwise relatively prime. - 13.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.3, “Primes and Greatest Common Divisors” (4.3.6, “Greatest Common Divisors and Least Common Multiples”), p. 281 (the whole topic: pp. 281–282).
“where each exponent is a nonnegative integer, and where all primes occurring in the prime factorization of either a or b are included in both factorizations, with zero exponents if necessary.”
Used for: with exponents, a prime missing from a number is given exponent 0, and each prime is taken with the smaller exponent. - 14.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.3, “Primes and Greatest Common Divisors” (4.3.7, “The Euclidean Algorithm”), p. 282 (the whole topic: pp. 282–284).
“Computing the greatest common divisor of two integers directly from the prime factorizations of these integers is inefficient. The reason is that it is time-consuming to find prime factorizations.”
Used for: for large numbers, finding the gcd from the factorizations is slow. - 15.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.4, “The Euclidean Algorithm”, Theorem 2.7, p. 28 (the whole topic: pp. 28–29).
“An important consequence of the Euclidean Algorithm is the following theorem. Theorem 2.7. If k > 0, then gcd(ka, kb) = k gcd(a, b).”
Used for: gcd(k × a, k × b) = k × gcd(a, b) is a standard theorem. - 16.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 2, “Divisibility Theory in the Integers”, section 2.3, “The Greatest Common Divisor”, Theorem 2.5, p. 24 (the whole topic: pp. 23–24).
“Our next result seems mild enough, but is of fundamental importance. Theorem 2.5 Euclid’s lemma. If a | bc, with gcd(a, b) = 1, then a | c.”
Used for: Burton calls the statement “if a | b × c and gcd(a, b) = 1, then a | c” Euclid’s lemma.