Steply

Write gcd(240, 46) as 240x + 46y

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

Step by step

The question

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

gcd(240, 46) = 240x + 46y

1 Divide the bigger by the smaller

Divide the bigger number by the smaller: 46 goes into 240 5 times, and 10 is left over.

240 = 5 × 46 + 10

Here is the trick.

A number that goes into 240 and 46 also goes into 10, because 10 is 240 minus 5 × 46.

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

gcd(240, 46) = gcd(46, 10)

2 Keep going

Now the same with 46 and 10: the divisor moves left, the remainder becomes the new divisor.

46 = 4 × 10 + 6

10 = 1 × 6 + 4.

10 = 1 × 6 + 4

6 = 1 × 4 + 2.

6 = 1 × 4 + 2

4 = 2 × 2, and the remainder is 0.

We stop.

4 = 2 × 2 + 0

3 The last remainder before 0

Careful!

0 only tells us to stop.

The answer is the last remainder before it: 2.

Careful: not gcd(240, 46) = 0 ✗

The last remainder that is not 0 is 2.

So gcd(240, 46) = 2.

gcd(240, 46) = 2

4 Go back up

Start from the second last row, written for 2: 2 = 6 − 1 × 4.

2 = 6 − 1 × 4

4 is the remainder of the row above: 10 − 1 × 6.

Swap it in.

= 6 − 1 × (10 − 1 × 6)

Open the bracket and count the 6s: 1 + 1 × 1 = 2.

= 2 × 6 − 1 × 10

6 is the remainder of the row above: 46 − 4 × 10.

Swap it in.

= 2 × (46 − 4 × 10) − 1 × 10

Open the bracket and count the 10s: −1 − 2 × 4 = −9.

= 2 × 46 − 9 × 10

10 is the remainder of the row above: 240 − 5 × 46.

Swap it in.

= 2 × 46 − 9 × (240 − 5 × 46)

Open the bracket and count the 46s: 2 + 9 × 5 = 47.

= 47 × 46 − 9 × 240

So x = −9 and y = 47.

2 = 240 × (−9) + 46 × 47

5 Check

Put them in: 240 × (−9) plus 46 × 47 is 2.

Right!

240 × (−9) + 46 × 47 = −2160 + 2162 = 2

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(240, 46) = 2

Your turn

Try this one yourself, then check:

gcd(18, 8) = 18x + 8y
Show the answer
x = 1, y = −2

More from Euclid's algorithm

The whole lesson: Euclid's algorithm →