Steply

Euclid's algorithm

Discrete Math · 20 problems, easy to harder

▶ Watch the first one solved

How we do it

  1. Divide the bigger by the smaller
  2. Keep going
  3. The last remainder before 0
  4. Go back up
  5. Check

The steps for Write gcd(252, 198) as 252x + 198y. Every solution names its steps, so you always know what comes next.

Worked examples

Calculate gcd(48, 18) by Euclid's algorithm Easy

The question

Question: find gcd(48, 18) by Euclid's algorithm.

gcd(48, 18)

1 Divide the bigger by the smaller

Divide the bigger number by the smaller: 18 goes into 48 2 times, and 12 is left over.

48 = 2 × 18 + 12

Here is the trick.

A number that goes into 48 and 18 also goes into 12, because 12 is 48 minus 2 × 18.

So the gcd does not change, and the numbers get smaller.

gcd(48, 18) = gcd(18, 12)

2 Keep going

Now the same with 18 and 12: the divisor moves left, the remainder becomes the new divisor.

18 = 1 × 12 + 6

12 = 2 × 6, and the remainder is 0.

We stop.

12 = 2 × 6 + 0

3 The last remainder before 0

Careful!

0 only tells us to stop.

The answer is the last remainder before it: 6.

Careful: not gcd(48, 18) = 0 ✗

The last remainder that is not 0 is 6.

So gcd(48, 18) = 6.

gcd(48, 18) = 6

4 Check

6 goes into both: 48 ÷ 6 is 8, and 18 ÷ 6 is 3.

48 ÷ 6 = 8, 18 ÷ 6 = 3

And 8 and 3 have no common factor, so nothing bigger than 6 goes into both.

Right!

8 and 3: no common factor

Let's look back.

First: divide the bigger by the smaller.

Then: keep going.

Then: the last remainder before 0.

Last: check.

Answer
gcd(48, 18) = 6

▶ Watch it solved

Calculate gcd(252, 198) by Euclid's algorithm Medium

The question

Question: find gcd(252, 198) by Euclid's algorithm.

gcd(252, 198)

1 Divide the bigger by the smaller

Divide the bigger number by the smaller: 198 goes into 252 once, and 54 is left over.

252 = 1 × 198 + 54

Here is the trick.

A number that goes into 252 and 198 also goes into 54, because 54 is 252 minus 1 × 198.

So the gcd does not change, and the numbers get smaller.

gcd(252, 198) = gcd(198, 54)

2 Keep going

Now the same with 198 and 54: the divisor moves left, the remainder becomes the new divisor.

198 = 3 × 54 + 36

54 = 1 × 36 + 18.

54 = 1 × 36 + 18

36 = 2 × 18, and the remainder is 0.

We stop.

36 = 2 × 18 + 0

3 The last remainder before 0

Careful!

0 only tells us to stop.

The answer is the last remainder before it: 18.

Careful: not gcd(252, 198) = 0 ✗

The last remainder that is not 0 is 18.

So gcd(252, 198) = 18.

gcd(252, 198) = 18

4 Check

18 goes into both: 252 ÷ 18 is 14, and 198 ÷ 18 is 11.

252 ÷ 18 = 14, 198 ÷ 18 = 11

And 14 and 11 have no common factor, so nothing bigger than 18 goes into both.

Right!

14 and 11: no common factor

Let's look back.

First: divide the bigger by the smaller.

Then: keep going.

Then: the last remainder before 0.

Last: check.

Answer
gcd(252, 198) = 18

▶ Watch it solved

Write gcd(252, 198) as 252x + 198y Harder

The question

Question: write gcd(252, 198) as 252x + 198y, with whole numbers x and y.

gcd(252, 198) = 252x + 198y

1 Divide the bigger by the smaller

Divide the bigger number by the smaller: 198 goes into 252 once, and 54 is left over.

252 = 1 × 198 + 54

Here is the trick.

A number that goes into 252 and 198 also goes into 54, because 54 is 252 minus 1 × 198.

So the gcd does not change, and the numbers get smaller.

gcd(252, 198) = gcd(198, 54)

2 Keep going

Now the same with 198 and 54: the divisor moves left, the remainder becomes the new divisor.

198 = 3 × 54 + 36

54 = 1 × 36 + 18.

54 = 1 × 36 + 18

36 = 2 × 18, and the remainder is 0.

We stop.

36 = 2 × 18 + 0

3 The last remainder before 0

Careful!

0 only tells us to stop.

The answer is the last remainder before it: 18.

Careful: not gcd(252, 198) = 0 ✗

The last remainder that is not 0 is 18.

So gcd(252, 198) = 18.

gcd(252, 198) = 18

4 Go back up

Start from the second last row, written for 18: 18 = 54 − 1 × 36.

18 = 54 − 1 × 36

36 is the remainder of the row above: 198 − 3 × 54.

Swap it in.

= 54 − 1 × (198 − 3 × 54)

Open the bracket and count the 54s: 1 + 1 × 3 = 4.

= 4 × 54 − 1 × 198

54 is the remainder of the row above: 252 − 1 × 198.

Swap it in.

= 4 × (252 − 1 × 198) − 1 × 198

Open the bracket and count the 198s: −1 − 4 × 1 = −5.

= 4 × 252 − 5 × 198

So x = 4 and y = −5.

18 = 252 × 4 + 198 × (−5)

5 Check

Put them in: 252 × 4 plus 198 × (−5) is 18.

Right!

252 × 4 + 198 × (−5) = 1008 − 990 = 18

Let's look back.

First: divide the bigger by the smaller.

Then: keep going.

Then: the last remainder before 0.

Then: go back up.

Last: check.

Answer
gcd(252, 198) = 18

▶ Watch it solved

Practice

Try each one, then open the answer. Stuck? Open the problem to watch every step.

Easy

  1. gcd(48, 18) by Euclid's algorithm
    Answer
    gcd(48, 18) = 6
  2. gcd(84, 36) by Euclid's algorithm
    Answer
    gcd(84, 36) = 12
  3. gcd(100, 75) by Euclid's algorithm
    Answer
    gcd(100, 75) = 25
  4. gcd(56, 42) by Euclid's algorithm
    Answer
    gcd(56, 42) = 14
  5. gcd(91, 35) by Euclid's algorithm
    Answer
    gcd(91, 35) = 7

Medium

  1. gcd(252, 198) by Euclid's algorithm
    Answer
    gcd(252, 198) = 18
  2. use the Euclidean algorithm to find gcd(1071, 462)
    Answer
    gcd(1071, 462) = 21
  3. gcd(270, 192) by Euclid's algorithm
    Answer
    gcd(270, 192) = 6
  4. gcd(210, 154) by Euclid's algorithm
    Answer
    gcd(210, 154) = 14
  5. gcd(330, 156) by Euclid's algorithm
    Answer
    gcd(330, 156) = 6
  6. gcd(612, 342) by Euclid's algorithm
    Answer
    gcd(612, 342) = 18
  7. gcd(1260, 198) by Euclid's algorithm
    Answer
    gcd(1260, 198) = 18
  8. gcd(462, 132) by Euclid's algorithm
    Answer
    gcd(462, 132) = 66
  9. gcd(299, 221) by Euclid's algorithm
    Answer
    gcd(299, 221) = 13

Harder

  1. write gcd(252, 198) as 252x + 198y
    Answer
    gcd(252, 198) = 18
  2. write gcd(48, 18) as 48x + 18y
    Answer
    gcd(48, 18) = 6
  3. write gcd(84, 36) as 84x + 36y
    Answer
    gcd(84, 36) = 12
  4. write gcd(240, 46) as 240x + 46y
    Answer
    gcd(240, 46) = 2
  5. write gcd(161, 28) as 161x + 28y
    Answer
    gcd(161, 28) = 7
  6. write gcd(99, 78) as 99x + 78y
    Answer
    gcd(99, 78) = 3