Home page for accesible maths 4 Number theory

Style control - access keys in brackets

Font (2 3) - + Letter spacing (4 5) - + Word spacing (6 7) - + Line spacing (8 9) - +

4.3 The Euclidean algorithm

In this section we shall develop an efficient method to calculate hcf(a,b)\mathrm{hcf}(a,b) for a,b{0}a,b\in\mathbb{Z}\setminus\{0\} which does not depend on finding all the factors of aa and bb themselves. Moreover, this method will give us an explicit way of determining r,sr,s\in\mathbb{Z} such that hcf(a,b)=ra+sb\mathrm{hcf}(a,b)=ra+sb.

We begin by noting the effect of ‘‘division with remainder’’ on highest common factors.

Proposition 4.3.1

If a,b,q,ra,b,q,r\in\mathbb{Z} with b0b\neq 0 and a=qb+ra=qb+r, then hcf(a,b)=hcf(b,r)\mathrm{hcf}(a,b)=\mathrm{hcf}(b,r).

Example 4.3.2

38=48+638=4\cdot 8+6, and hcf(38,8)=2=hcf(8,6).\mathrm{hcf}(38,8)=2=\mathrm{hcf}(8,6).

Proof. Let dd\in\mathbb{Z} be a factor of bb. We begin by showing that dd divides aa if and only if dd divides rr. Indeed, by Lemma 4.2.13, if dd divides aa, then dd divides a-qb=ra-qb=r, and conversely, if dd divides rr, then dd divides qb+r=aqb+r=a. Thus dd is a common factor of aa and bb if and only if dd is a common factor of bb and rr, and therefore hcf(a,b)=hcf(b,r)\mathrm{hcf}(a,b)=\mathrm{hcf}(b,r). \Box

Now suppose that |a|>|b||a|>|b| (otherwise we interchange them, as Remark 4.2.5(iii) allows us to). Then we can use ‘‘division with remainder’’ to replace the pair of numbers aa and bb with the pair bb and rr, without changing the highest common factor. Since the new pair is ‘‘smaller’’ than the old one, we have simplified the problem. This suggests that we can use this technique repeatedly, making each old divisor the new number to be divided, and each old remainder the new divisor, continuing until the divison leaves no remainder:

a\displaystyle a =q1b+r1\displaystyle=q_{1}b+r_{1} (with 0<r1<|b|)\displaystyle(\hbox{with}\ 0<r_{1}<|b|)
b\displaystyle b =q2r1+r2\displaystyle=q_{2}r_{1}+r_{2} (with 0<r2<r1)\displaystyle(\hbox{with}\ 0<r_{2}<r_{1})
r1\displaystyle r_{1} =q3r2+r3\displaystyle=q_{3}r_{2}+r_{3} (with 0<r3<r2)\displaystyle(\hbox{with}\ 0<r_{3}<r_{2})
\displaystyle\;\;\vdots
rn-3\displaystyle r_{n-3} =qn-1rn-2+rn-1\displaystyle=q_{n-1}r_{n-2}+r_{n-1} (with 0<rn-1<rn-2)\displaystyle(\hbox{with}\ 0<r_{n-1}<r_{n-2})
rn-2\displaystyle r_{n-2} =qnrn-1+0.\displaystyle=q_{n}r_{n-1}+0.

This process is called the Euclidean algorithm; it must terminate since the remainders rjr_{j} form a strictly decreasing sequence of natural numbers: r1>r2>>0r_{1}>r_{2}>\cdots>0. By repeated use of Proposition 4.3.1, we see that the last divisor rn-1r_{n-1} is the highest common factor, because

hcf(a,b)=hcf(b,r1)=hcf(r1,r2)==hcf(rn-2,rn-1)=rn-1.\mathrm{hcf}(a,b)=\mathrm{hcf}(b,r_{1})=\mathrm{hcf}(r_{1},r_{2})=\cdots=% \mathrm{hcf}(r_{n-2},r_{n-1})=r_{n-1}.

We may then reverse the steps to obtain the highest common factor as an integral linear combination of aa and bb.

Some examples will clarify how this works in practice.

Example 4.3.3

Find hcf(115,25)\mathrm{hcf}(115,25), and express it as an integral linear combination of 115115 and 2525.

Solution.

115=425+15and5=15-1025=115+10=15-(25-15)15=110+5=215-2510=25+0=2(115-425)-25so hcf(25,115)=5,=2115+(-9)25.\begin{array}[]{rlcrl}115&\!\!\!=4\cdot 25+15&\qquad\text{and}&5=&15-10\\ 25&\!\!\!=1\cdot 15+10&&=&15-(25-15)\\ 15&\!\!\!=1\cdot 10+5&&=&2\cdot 15-25\\ 10&\!\!\!=2\cdot 5+0&&=&2(115-4\cdot 25)-25\\ \hbox{so }\mathrm{hcf}(25,115)&\!\!\!=5,&&=&2\cdot 115+(-9)25.\end{array}
Example 4.3.4

Find hcf(1152,930)\mathrm{hcf}(1152,930), and express it as an integral linear combination of 11521152 and 930930.

Solution.

1152=1930+222and6=42-312930=4222+42=42-3(222-542)222=542+12=1642-322242=312+6=16(930-4222)-322212=26+0=16930-67222=16930-67(1152-930)so hcf(1152,930)=6,=83930-671152.\begin{array}[]{rlcrl}1152&\!\!\!=1\cdot 930+222&\quad\text{and}&6=&42-3\cdot 1% 2\\ 930&\!\!\!=4\cdot 222+42&&=&42-3(222-5\cdot 42)\\ 222&\!\!\!=5\cdot 42+12&&=&16\cdot 42-3\cdot 222\\ 42&\!\!\!=3\cdot 12+6&&=&16(930-4\cdot 222)-3\cdot 222\\ 12&\!\!\!=2\cdot 6+0&&=&16\cdot 930-67\cdot 222\\ &&&=&16\cdot 930-67(1152-930)\\ \hbox{so }\mathrm{hcf}(1152,930)&\!\!\!=6,&&=&83\cdot 930-67\cdot 1152.\end{array}