The Euclides algorithm

The highest common factor between two integers is the biggest number that divides both.

Example

For example, if we have 20 and 16, the highest common factor between the two is 4, since:

The divisors of 20 are: 1, 2, 4, 5, 10 and 20

The divisors of 16 are: 1, 2, 4 and 16

The numbers that divide either 20 or 16 are: 1, 2 and 4, and clearly the biggest is 4. So, the highest common factor between 20 and 16 is 4, and it is written as hcf(20,16)=4.

Nevertheless, calculating the highest common factor between two numbers can turn out to be much more complicated for very big numbers.

To do so, a method exists which is known as algorithm of Euclides, which, although at first it looks a little bit strange at first, after practiced, it turns out to be much simpler than other methods.

Furthermore, it is also useful for solving diophantine equations.

The Euclides algorithm is based on the definition of three sequences of numbers: the first one is called rj, the second one will be called sj and the third one tj.

The Euclides algorithm consists in doing the following steps:

  • Two numbers are taken:a0, b>0. We want to calculate hcf(a,b) (the highest common factor between a and b). For example, we might take a=10 and b=5.

  • We define:r0=a,r1=bs0=1,s1=0t0=0,t1=1 For example with a=10 and b=5, we would have: :r0=10,r1=5s0=1,s1=0t0=0,t1=1

  • For j2, we do the integer division of rja by rj1. We call the result qj1 and to the remainder rj. In the previous example, if we want to calculate r2 and q1 (that is to say, j=2) it is necessary to do the integer division between r0=10 and r1=5. It is clear that the result of the divisón is 2 with remainder 0, and therefore we write q1=2 and r2=0.

  • Now, we define:sj=sj2sj1qj1tj=tj2tj1qj1 In the previous example we had: s2=s0s1q1=101=1t2=t0t1q1=012=2

  • When there is one rn+1=0, then we have hcf(a,b)=rn (that is to say, that of the previous step!). Furthermore, it is also satisfied that: hcf(a,b)=sna+tnb (sn and tn are also those of the previous step).

Returning to the example that we used on the previous steps, we have seen that for j=2 it is already satisfied that r2=0. Therefore, the highest common factor between 10 and 5 is r1 (that of the previous step), that is to say, 5.

Besides, the last equality says to us that: hcf(10,5)=s110+t15=010+15=0