1. Euclid's Algorithm0%

Number Theory · Topic 1 of 2

1. Euclid's Algorithm

Video coming soon2 worked examples

Theory

Euclid's algorithm finds the greatest common divisor (gcd) of two positive integers by repeated division. Write each step as a=qb+ra = qb + r with 0r<b0 \leq r < b, then replace (a,b)(a, b) with (b,r)(b, r) and repeat until the remainder is 00. The last non-zero remainder is the gcd.

The gcd can then be written as a linear combination of the two numbers, gcd(a,b)=ax+by\gcd(a,b) = ax + by for integers x,yx, y, by back-substituting through the equations.

The Golden Rule: keep dividing until the remainder is 00; the gcd is the last non-zero remainder. For the linear combination, work backwards through the algorithm's equations.

⚠️ Common Examiner Traps

  • Reading the wrong remainder: the gcd is the last non-zero remainder, not the final 00.
  • Back-substitution slips: substitute one equation at a time and keep the two original numbers visible so the coefficients stay correct.
  • Division form: each line must be a=qb+ra = qb + r with 0r<b0 \leq r < b.

Worked examples

Example 1

Use Euclid's algorithm to find gcd(1071,462)\gcd(1071, 462).

Step 1: Apply repeated division:

1071=2×462+147462=3×147+21147=7×21+0\begin{aligned} 1071 &= 2 \times 462 + 147 \\ 462 &= 3 \times 147 + 21 \\ 147 &= 7 \times 21 + 0 \end{aligned}

Step 2: The last non-zero remainder is 2121, so gcd(1071,462)=21\gcd(1071, 462) = 21.

Example 2

Express gcd(1071,462)=21\gcd(1071, 462) = 21 as a linear combination of 10711071 and 462462.

Step 1: Rearrange the algorithm's equations to make the remainders the subject:

21=4623×147147=10712×46221 = 462 - 3 \times 147 \qquad 147 = 1071 - 2 \times 462

Step 2: Substitute the expression for 147147 and collect:

21=4623(10712×462)=7×4623×107121 = 462 - 3(1071 - 2 \times 462) = 7 \times 462 - 3 \times 1071

Step 3: So 21=(3)(1071)+(7)(462)21 = (-3)(1071) + (7)(462).