Steply

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

Step by step, with the reason for every step · Euclid's algorithm · Discrete Math

Step by step

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

Your turn

Try this one yourself, then check:

gcd(187, 121) = 187x + 121y
Show the answer
x = 2, y = −3

More from Euclid's algorithm

The whole lesson: Euclid's algorithm →