Skip to content
Number Theory · Chapter 23

GCD & LCM

Build GCDs and LCMs from prime exponents, shrink big pairs with the Euclidean algorithm, and use Bézout's identity to see exactly which totals two step sizes can reach.

You'll need
open on YouTube
23.0a0%

GCD and LCM from Prime Factors

In this section you will be able to find a GCD or an LCM from prime factorizations, and use GCD × LCM = m × n.

Ten horses run laps of 1,2,…,101, 2, \ldots, 10 minutes. When are they all back at the start together? They meet at every common multiple of 11 through 1010, and the first time is the LCM, 25202520.

Every GCD and LCM question becomes easy once you write the numbers as products of primes. Shared primes go in the middle of the diagram. The GCD keeps only what both numbers share; the LCM keeps everything.

Look: for each prime, the GCD takes the lower exponent and the LCM takes the higher one. Lower plus higher is the sum of both exponents, and that is why gcd⁡(m,n)⋅lcm⁡(m,n)=mn\gcd(m, n) \cdot \operatorname{lcm}(m, n) = mn.

Exploreplay first, formulas later

24 = 2^3 × 3, 36 = 2^2 × 3^2: GCD = 12, LCM = 72

243622233
Shared primes sit in the middle. Press a button to build the GCD or the LCM.
Product of shared tokens: 12. Product of all tokens: 72.

24 has 4 prime tokens, 36 has 4; 3 are shared

Name it

Definition 23.0.1 · Greatest Common Divisor

The Greatest Common Divisor (GCD) of two or more nonzero integers is the largest positive integer that divides each of them.

It is also called the GCF (Greatest Common Factor). The two names mean the same thing.

Definition 23.0.2 · Least Common Multiple

The Least Common Multiple (LCM) of two or more nonzero integers is the smallest positive integer that is divisible by each of them.

Concept 23.0.3 · GCD and LCM from prime factorizations

gcd⁡(m,n)\gcd(m, n) takes the lowest exponent of each prime in the prime factorizations of mm and nn.

lcm⁡(m,n)\operatorname{lcm}(m, n) takes the highest exponent of each prime.

For example, 24=23⋅324 = 2^{3} \cdot 3 and 36=22⋅3236 = 2^{2} \cdot 3^{2}, so gcd⁡(24,36)=22⋅3=12\gcd(24, 36) = 2^{2} \cdot 3 = 12 and lcm⁡(24,36)=23⋅32=72\operatorname{lcm}(24, 36) = 2^{3} \cdot 3^{2} = 72.

Theorem 23.0.4 · GCD × LCM

The product of the GCD and the LCM of two numbers equals the product of the two numbers:

gcd⁡(m,n)⋅lcm⁡(m,n)=m⋅n.\gcd(m, n) \cdot \operatorname{lcm}(m, n) = m \cdot n.

Theorem 23.0.5 · Pulling out a common factor

If two numbers have a common factor cc, then

gcd⁡(ac,bc)=c⋅gcd⁡(a,b).\gcd(ac, bc) = c \cdot \gcd(a, b).

Watch itpredict, then reveal

Example 23.1

Omega Learn

Two numbers aa and bb satisfy the condition

lcm⁡(gcd⁡(24,a),gcd⁡(a,b))=lcm⁡(gcd⁡(24,b),gcd⁡(a,b)).\operatorname{lcm}(\gcd(24, a), \gcd(a, b)) = \operatorname{lcm}(\gcd(24, b), \gcd(a, b)).

If a=2ba = 2b, what is the smallest possible value of a+ba + b?

Prime Venn (its total is revealed at the end of the example)

2442322
GCD = 2 × 2 = 4
primein 24in 4lowesthighest
23223
31001
Product of shared tokens: 4. Product of all tokens: 24.

GCD(24, 4) = 2 × 2 = 4

  1. 1

    Since a=2ba = 2b, what is gcd⁡(a,b)=gcd⁡(2b,b)\gcd(a, b) = \gcd(2b, b)?

    Predict first:
    Click a choice or type its letter (A–E).
open on YouTube

Try it

Problem 23.1.7(additional)

AMC 12

Let NN be the second smallest positive integer that is divisible by every positive integer less than 77. What is the sum of the digits of NN?

Problem 23.1.8(additional)

AMC 10

There are 1010 horses, named Horse 11, Horse 22, …\ldots, Horse 1010. They get their names from how many minutes it takes them to run one lap around a circular race track: Horse kk runs one lap in exactly kk minutes. At time 00 all the horses are together at the starting point on the track. The horses start running in the same direction, and they keep running around the circular track at their constant speeds. The least time S>0S > 0, in minutes, at which all 1010 horses will again simultaneously be at the starting point is S=2520S = 2520. Let T>0T > 0 be the least time, in minutes, such that at least 55 of the horses are again at the starting point. What is the sum of the digits of TT?

Contest cornerreal contest problems

Problem 23.1.1

AMC 10

Let a,b,ca, b, c, and dd be positive integers such that gcd⁡(a,b)=24\gcd(a, b) = 24, gcd⁡(b,c)=36\gcd(b, c) = 36, gcd⁡(c,d)=54\gcd(c, d) = 54, and 70<gcd⁡(d,a)<10070 < \gcd(d, a) < 100. Which of the following must be a divisor of aa?

Click a choice or type its letter (A–E).

Problem 23.1.4

AMC 10

How many ordered pairs (a,b)(a, b) of positive integers satisfy the equation

a⋅b+63=20⋅lcm⁡(a,b)+12⋅gcd⁡(a,b),a \cdot b + 63 = 20 \cdot \operatorname{lcm}(a, b) + 12 \cdot \gcd(a, b),

where gcd⁡(a,b)\gcd(a, b) denotes the greatest common divisor of aa and bb, and lcm⁡(a,b)\operatorname{lcm}(a, b) denotes their least common multiple?

Problem 23.1.6

AMC 12

Suppose that a,b,ca, b, c, and dd are positive integers satisfying all of the following relations:

abcd=26⋅39⋅57lcm⁡(a,b)=23⋅32⋅53lcm⁡(a,c)=23⋅33⋅53lcm⁡(a,d)=23⋅33⋅53lcm⁡(b,c)=21⋅33⋅52lcm⁡(b,d)=22⋅33⋅52lcm⁡(c,d)=22⋅33⋅52\begin{aligned} abcd &= 2^{6} \cdot 3^{9} \cdot 5^{7} \\ \operatorname{lcm}(a, b) &= 2^{3} \cdot 3^{2} \cdot 5^{3} \\ \operatorname{lcm}(a, c) &= 2^{3} \cdot 3^{3} \cdot 5^{3} \\ \operatorname{lcm}(a, d) &= 2^{3} \cdot 3^{3} \cdot 5^{3} \\ \operatorname{lcm}(b, c) &= 2^{1} \cdot 3^{3} \cdot 5^{2} \\ \operatorname{lcm}(b, d) &= 2^{2} \cdot 3^{3} \cdot 5^{2} \\ \operatorname{lcm}(c, d) &= 2^{2} \cdot 3^{3} \cdot 5^{2} \end{aligned}

What is gcd⁡(a,b,c,d)\gcd(a, b, c, d)?

Click a choice or type its letter (A–E).

Problem 23.1.13(additional)

AMC 12

How many positive integers nn are there such that nn is a multiple of 55, and the least common multiple of 5!5! and nn equals 55 times the greatest common divisor of 10!10! and nn?

Checkpoint for section 23.0a

Get 2 of 3 right to master this section. One try each, no hints.
1

What is gcd⁡(84,120)\gcd(84, 120)?

2

What is lcm⁡(84,120)\operatorname{lcm}(84, 120)?

3

Two positive integers have GCD 66 and LCM 180180. One of them is 3636. What is the other?

23.0b0%

The Euclidean Algorithm

In this section you will be able to find the GCD of big numbers, or of expressions in n, by repeated subtraction.

What is gcd⁡(186,92)\gcd(186, 92)? Factoring works, but there is a faster way: take 9292 away from 186186 twice. Anything that divides both numbers also divides what is left.

Cut the biggest possible squares off an x×yx \times y rectangle. The leftover strip has the same common divisors as the rectangle you started with. Keep cutting: the last square’s side is the GCD.

The same trick works on expressions. To find gcd⁡(100+n2, 100+(n+1)2)\gcd(100 + n^{2},\ 100 + (n + 1)^{2}), subtract one from the other and the n2n^{2} disappears.

Exploreplay first, formulas later

186 × 92 rectangle, 0 of 2 cuts: gcd(186, 92); GCD = 2

gcd(186, 92)

Squares cut so far: 0. Left over: a 186 × 92 rectangle.

gcd(186, 92)

Name it

Theorem 23.0.6 · Euclidean Algorithm

gcd⁡(x,y)=gcd⁡(x−ky, y)\gcd(x, y) = \gcd(x - ky,\ y)

where x>yx > y and kk is a positive integer.

Watch itpredict, then reveal

Example 23.2

AIME

The numbers in the sequence 101,104,109,116,…101, 104, 109, 116, \ldots are of the form an=100+n2a_n = 100 + n^{2}, where n=1,2,3,…n = 1, 2, 3, \ldots For each nn, let dnd_n be the greatest common divisor of ana_n and an+1a_{n+1}. Find the maximum value of dnd_n as nn ranges through the positive integers.

Euclid's square tiles (its total is revealed at the end of the example)

gcd(40501, 40100)

Squares cut so far: 0. Left over: a 40501 × 40100 rectangle.

gcd(40501, 40100)

  1. 1

    What is an+1−ana_{n+1} - a_n?

    Predict first:
open on YouTube

Contest cornerreal contest problems

Problem 23.1.3

AIME

This problem also appears in the book as 22.1.5.

What is the largest positive integer nn for which n3+100n^{3} + 100 is divisible by n+10n + 10?

Problem 23.1.15(additional)

AMC 10

Let nn be the least positive integer greater than 10001000 for which

gcd⁡(63,n+120)=21andgcd⁡(n+63,120)=60.\gcd(63, n + 120) = 21 \quad\text{and}\quad \gcd(n + 63, 120) = 60.

What is the sum of the digits of nn?

Checkpoint for section 23.0b

Get 2 of 3 right to master this section. One try each, no hints.
1

Use the Euclidean algorithm to find gcd⁡(391,299)\gcd(391, 299).

2

As nn runs over the positive integers, what is the largest possible value of gcd⁡(n2+1, n+1)\gcd(n^{2} + 1,\ n + 1)?

3

What is gcd⁡(212−1, 28−1)\gcd(2^{12} - 1,\ 2^{8} - 1)?

23.0c0%

Bézout's Identity

In this section you will be able to decide which totals ax + by can reach, using Bézout's identity.

A token sits at 00 and can jump 66 or 1010 to the left or right. Can it ever land on 33? Every jump keeps it on an even number, so no.

Every total 6x+10y6x + 10y is a multiple of gcd⁡(6,10)=2\gcd(6, 10) = 2. The surprise is the other direction: every multiple of 22 can be reached. Running the Euclidean algorithm backwards finds the jumps.

So ax+by=cax + by = c has integer solutions exactly when gcd⁡(a,b)\gcd(a, b) divides cc. Look: this also proves that two expressions are coprime. If some combination of them equals 11, their GCD must be 11.

Exploreplay first, formulas later

Steps 6 and 10: x·6 + y·10 reaches exactly the multiples of gcd = 2

step a6
step b10
target—
−60−40−2002040600
0·6 + 0·10 = 0

The token is at 0·6 + 0·10 = 0.

Name it

Theorem 23.0.8 · Bézout's Identity

The equation

ax+by=cax + by = c

has integer solutions x,yx, y if and only if gcd⁡(a,b)\gcd(a, b) divides cc.

Contest cornerreal contest problems

Problem 23.1.2

IMO

This problem also appears in the book as 22.1.4.

Prove that the fraction 21n+414n+3\dfrac{21n+4}{14n+3} is irreducible for every natural number nn.

gcd(21n + 4, 14n + 3) divides 1; at n = 1 the steps are 25 and 17. Steps 25 and 17: x·25 + y·17 reaches exactly the multiples of gcd = 1

n1
target—
−60−40−2002040600
0·25 + 0·17 = 0

At n = 1: a = 25, b = 17.

Euclid on the expressions
gcd(21n + 4, 14n + 3) = ? (hidden until the end of the example)
21n + 4 = 25, 14n + 3 = 17

The token is at 0·25 + 0·17 = 0.

This one asks for a proof. Write yours on paper, use the hints if you need them, then compare it with the written proof.

Checkpoint for section 23.0c

Get 2 of 3 right to master this section. One try each, no hints.
1

Are there integers x,yx, y with 12x+18y=1512x + 18y = 15?

Click a choice or type its letter (A–E).
2

What is the smallest positive value of 12x+42y12x + 42y over all integers xx and yy?

3

A token starts at 00 on the number line and moves by steps of ±8\pm 8 and ±14\pm 14. Which of these can it land on?

Click a choice or type its letter (A–E).
23.1

Practice Problems

In this section you will be able to mix prime exponents, Euclid and Bézout on harder contest problems.

Time to mix it all up. These problems need prime exponents, Euclid’s subtraction and a little parity, often at once. Every problem has three hints if you get stuck.

Want every problem from this chapter on one page? Open the problem set.

Contest cornerreal contest problems

Problem 23.1.5

AMC 10/12

Suppose aa, bb, and cc are positive integers such that

a14+b15=c210.\frac{a}{14} + \frac{b}{15} = \frac{c}{210}.

Which of the following statements are necessarily true?

I. If gcd⁡(a,14)=1\gcd(a, 14) = 1 or gcd⁡(b,15)=1\gcd(b, 15) = 1 or both, then gcd⁡(c,210)=1\gcd(c, 210) = 1.

II. If gcd⁡(c,210)=1\gcd(c, 210) = 1, then gcd⁡(a,14)=1\gcd(a, 14) = 1 or gcd⁡(b,15)=1\gcd(b, 15) = 1 or both.

III. gcd⁡(c,210)=1\gcd(c, 210) = 1 if and only if gcd⁡(a,14)=gcd⁡(b,15)=1\gcd(a, 14) = \gcd(b, 15) = 1.

Click a choice or type its letter (A–E).

Problem 23.1.9(additional)

AMC 12

Suppose aa, bb, cc are positive integers such that

a+b+c=23a + b + c = 23

and

gcd⁡(a,b)+gcd⁡(b,c)+gcd⁡(c,a)=9.\gcd(a, b) + \gcd(b, c) + \gcd(c, a) = 9.

What is the sum of all possible distinct values of a2+b2+c2a^{2} + b^{2} + c^{2}?

Problem 23.1.10(additional)

AMC 12

This problem also appears in the book as 23.1.7.

Let NN be the second smallest positive integer that is divisible by every positive integer less than 77. What is the sum of the digits of NN?

Problem 23.1.11(additional)

AMC 12

Let nn be the smallest positive integer such that nn is divisible by 2020, n2n^{2} is a perfect cube, and n3n^{3} is a perfect square. What is the number of digits of nn?

Problem 23.1.12(additional)

AMC 12

Mary chose an even 44-digit number nn. She wrote down all the divisors of nn in increasing order from left to right: 1,2,…,n2,n1, 2, \ldots, \dfrac{n}{2}, n. At some moment Mary wrote 323323 as a divisor of nn. What is the smallest possible value of the next divisor written to the right of 323323?

Problem 23.1.14(additional)

AIME

For how many ordered pairs of positive integers (x,y)(x, y), with y<x≤100y < x \le 100, are both xy\dfrac{x}{y} and x+1y+1\dfrac{x+1}{y+1} integers?

Problem 23.1.16(additional)

AIMEChallenge

Consider the sequence (ak)k≥1(a_k)_{k \ge 1} of positive rational numbers defined by a1=20202021a_1 = \dfrac{2020}{2021} and for k≥1k \ge 1, if ak=mna_k = \dfrac{m}{n} for relatively prime positive integers mm and nn, then

ak+1=m+18n+19.a_{k+1} = \frac{m + 18}{n + 19}.

Determine the sum of all positive integers jj such that the rational number aja_j can be written in the form tt+1\dfrac{t}{t+1} for some positive integer tt.

Problem 23.1.17(additional)

AIMEChallenge

Find the number of ordered pairs (m,n)(m, n) such that mm and nn are positive integers in the set {1,2,…,30}\{1, 2, \ldots, 30\} and the greatest common divisor of 2m+12^{m} + 1 and 2n−12^{n} - 1 is not 11.