Math Core

Module 3.3 · Number Theory

GCD and LCM

Two buses leave the station together, one every 1212 minutes and one every 1818. When do they leave together again? A rectangle must be cut into the largest possible equal squares. How big are the squares? The first question asks for a least common multiple and the second for a greatest common divisor. Contest writers disguise these two ideas in many costumes.

Definitions

Definition

GCD and LCM

The greatest common divisor gcd⁡(a,b)\gcd(a, b) is the largest whole number that divides both aa and bb. (MATHCOUNTS often calls it the greatest common factor, GCF.)

The least common multiple lcm⁡(a,b)\operatorname{lcm}(a, b) is the smallest positive whole number that is a multiple of both aa and bb.

Using prime factorizations

Write both numbers as products of primes.

  • For the GCD, take each common prime to the smaller power.
  • For the LCM, take every prime that appears to the larger power.

Worked example: Factorization method

Find gcd⁡(168,180)\gcd(168, 180) and lcm⁡(168,180)\operatorname{lcm}(168, 180).

168=23⋅3⋅7168 = 2^3 \cdot 3 \cdot 7 and 180=22⋅32⋅5180 = 2^2 \cdot 3^2 \cdot 5.

  • GCD: smaller powers of the common primes 22 and 33: 22⋅3=122^2 \cdot 3 = 12.
  • LCM: larger power of every prime: 23⋅32⋅5⋅7=25202^3 \cdot 3^2 \cdot 5 \cdot 7 = 2520.

Notice that 12×2520=30,240=168×18012 \times 2520 = 30{,}240 = 168 \times 180. That's not a coincidence. For each prime, the GCD takes one of the two exponents and the LCM takes the other, so together they use every prime factor of aa and bb exactly once.

The product rule

For any two positive integers, gcd⁡(a,b)×lcm⁡(a,b)=a×b.\gcd(a, b) \times \operatorname{lcm}(a, b) = a \times b.

Common mistake

The product rule works for two numbers only. For three numbers, gcd⁡(a,b,c)⋅lcm⁡(a,b,c)\gcd(a,b,c) \cdot \operatorname{lcm}(a,b,c) is usually not abcabc. For example, gcd⁡(2,4,8)⋅lcm⁡(2,4,8)=2⋅8=16\gcd(2,4,8) \cdot \operatorname{lcm}(2,4,8) = 2 \cdot 8 = 16, but 2⋅4⋅8=642 \cdot 4 \cdot 8 = 64.

The Euclidean algorithm

Factoring large numbers is slow. Luckily, any number that divides both aa and bb also divides a−ba - b. So gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a, b) = \gcd(b, a - b), and you can subtract (or take remainders) repeatedly until the numbers are small.

Worked example: Euclidean algorithm

Find gcd⁡(391,667)\gcd(391, 667).

gcd⁡(391,667)=gcd⁡(391,276)667−391=276=gcd⁡(115,276)391−276=115=gcd⁡(115,46)276=2⋅115+46=gcd⁡(23,46)115=2⋅46+23=2346=2⋅23\begin{aligned} \gcd(391, 667) &= \gcd(391, 276) && 667 - 391 = 276 \\ &= \gcd(115, 276) && 391 - 276 = 115 \\ &= \gcd(115, 46) && 276 = 2 \cdot 115 + 46 \\ &= \gcd(23, 46) && 115 = 2 \cdot 46 + 23 \\ &= 23 && 46 = 2 \cdot 23 \end{aligned}

Indeed, 391=17⋅23391 = 17 \cdot 23 and 667=23⋅29667 = 23 \cdot 29.

Spotting GCD vs. LCM in word problems

  • "Together again," "at the same time," "repeating cycles" point to the LCM.
  • "Largest equal groups," "biggest square tiles," "cut into equal pieces with none left over" point to the GCD.

Worked example: Pairs with a given GCD and LCM

How many ordered pairs of positive integers (a,b)(a, b) have gcd⁡(a,b)=6\gcd(a, b) = 6 and lcm⁡(a,b)=72\operatorname{lcm}(a, b) = 72?

Write a=6xa = 6x and b=6yb = 6y where xx and yy share no common factor. Then lcm⁡(a,b)=6xy=72\operatorname{lcm}(a, b) = 6xy = 72, so xy=12=22⋅3xy = 12 = 2^2 \cdot 3. Since xx and yy share no prime, the whole 222^2 goes to one of them and the 33 goes to one of them. The choices are (x,y)=(1,12),(12,1),(4,3),(3,4)(x, y) = (1, 12), (12, 1), (4, 3), (3, 4).

That gives 4 ordered pairs: (6,72),(72,6),(24,18),(18,24)(6, 72), (72, 6), (24, 18), (18, 24).

Tip

The trick of writing a=gxa = gx, b=gyb = gy with gcd⁡(x,y)=1\gcd(x, y) = 1 turns almost every "given the GCD and LCM" problem into a counting problem about xx and yy.

Practice

Practice 1

What is the greatest common divisor of 8484 and 126126?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

What is the least common multiple of 1818, 2424 and 3030?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Three lights flash every 1212, 1818 and 3030 seconds. They all flash together at exactly noon. When is the next time they all flash together?

Practice 4

The GCD of two numbers is 66 and their LCM is 180180. One of the numbers is 3636. What is the other?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Use the Euclidean algorithm to find gcd⁡(1001,1573)\gcd(1001, 1573).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

An 8484 cm by 120120 cm sheet of paper is cut into identical squares, as large as possible, with no paper left over. How many squares are there?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

How many pairs of positive integers (a,b)(a, b) with a≤ba \le b have gcd⁡(a,b)=4\gcd(a, b) = 4 and lcm⁡(a,b)=120\operatorname{lcm}(a, b) = 120?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

What is the smallest positive integer that leaves a remainder of 11 when divided by each of 2,3,4,52, 3, 4, 5 and 66, and is divisible by 77?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice