Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Primary Math Master Class

Workshop

Name: _________________ Date: _____________

Euclidean Algorithm

In this workshop, we will study how to find the highest common factor of two large
whole numbers efficiently. Let us recall what you have learnt so far.

Definition 1 Let a and b be integers. We say that a is a factor of b if we can find an


integer k such that b = ka . In this case, we also say that b is a multiple of a.
Note: Whole numbers are positive integers. Integers also include zero and negative
integers.

Notation 2
(i) We write a | b to mean that a is a factor of b.
(ii) We write a /| b to mean that a is not a factor of b.
This is an abbreviation to make it easier for us to discuss our ideas.

Example 3
(i) 2 | 6 because 6= 2 × 3 and 3 is an integer.
(ii) 3 | 141 because _______________________________________________
(iii) 4 /| 18 because _______________________________________________

Definition 4 Let a, b and c be integers. Suppose a | b and a | c . We say that a is a


common factor of b and c. Among the common factors, the largest one is called the
highest common factor of b and c, denoted by hcf (b, c ) .

Definition 5 Let a, b and c be integers. Suppose a | c and b | c . We say that c is a


common multiple of a and b. Among the common multiples, the smallest one is
called the lowest common multiple of a and b, denoted by lcm(a, b ) .

Page 1-1
Primary Math Master Class Workshop: Euclidean Algorithm

Example 6
To find hcf (12,18 ) , we list the factors of each number.

The factors of 12 are: 1, 2, 3, 4, 6 and 12.


The factors of 18 are: 1, 2, 3, 6, 9 and 18.
The common factors of 12 and 18 are: _______________.
So, hcf (12,18 ) = _________

Besides the listing method shown above, are there other methods for finding
hcf (12,18 ) ? Write them below:

Exercise 7
Find (i) hcf (3988,8973) , (ii) hcf ( 792,1547 ) .

Page 1-2
Primary Math Master Class Workshop: Euclidean Algorithm

Some of you probably find the above exercise tedious or difficult, using the methods
that you know so far:
Method 1: Listing the factors
Method 2: Find prime factorization of numbers
Method 3: Find common factors using synthetic division

These methods have limitations. They require you to know the prime factorization of
the numbers you are investigating. If the prime factors are large, you have to spend
a lot of time using trial and error. Is there a more efficient method?

We will now try to find another method. Before that, we make some observations.

Observation 8 Let a and b be integers. Then we can always find integers q and r
a bq + r and 0 ≤ r < b . We call b the divisor, q the quotient, r the
such that =
remainder.

Example 9 Divide 127 by 7. Express this relationship as an equation.

Observation 10 Let a, b and c be integers such that a | b and a | c . Then a | bx + cy


for all integers x and y. (For example, a | b + c , a | 2b − 3c and so on.)
Proof:

Page 1-3
Primary Math Master Class Workshop: Euclidean Algorithm

a bq + r and 0 ≤ r < b .
Observation 11 Let a, b, q and r be integers such that =
Then hcf (a, b ) = hcf (b, r ) .
Proof:

Page 1-4
Primary Math Master Class Workshop: Euclidean Algorithm

We are now ready to explain the Euclidean Algorithm.


Algorithm 12 (Euclidean Algorithm) To find hcf (a, b ) ,

Step 1: Divide a by b to get the first remainder r1 and the first quotient q1 ,

where=
a bq1 + r1 and 0 ≤ r1 < b . If r1 = 0 , we can stop the algorithm

=
and deduce that hcf =
(a, b ) hcf (b,0) b (Use Observation 11).
Otherwise, continue to Step 2.

Step 2: Divide b by r1 to get the next remainder r2 and the next quotient q2 ,

where=
b r1q2 + r2 and 0 ≤ r2 < r1 . If r2 = 0 , we can stop the algorithm

=
and deduce that hcf =
(a, b ) hcf =
(b, r1 ) hcf (r1,0) r1 (Use Observation
11). Otherwise, continue to Step 3.

Step 3: Divide r1 by r2 to get the next remainder r3 and the next quotient q3 ,

where=
r1 r2q3 + r3 and 0 ≤ r3 < r2 . If r3 = 0 , we can stop the algorithm

=
and deduce that hcf =
(a, b ) hcf =
(b, r1 ) hcf =
(r1, r2 ) hcf (r2 ,0) r2 (Use
Observation 11). Otherwise, continue to Step 4.

(Fill in Step 4 yourself.)


Step 4: Divide _____ by _____ to get the next remainder ______ and the next
quotient _____ , where ______________ and __________.
If _________ , we can stop the algorithm and deduce that
_____________________________________________________
(Use Observation 11). Otherwise, continue to the next step.

Is it possible that we never get to stop the algorithm?

Page 1-5
Primary Math Master Class Workshop: Euclidean Algorithm

Example 13 Use Euclidean Algorithm to find hcf (123,456) .


Solution:
456= 123 × 3 + 87
123= 87 × 1 + 36
87 = 36 × 2 + 15
36 = 15 × 2 + 6
15 = 6 × 2 + 3
6 = 3×2 + 0
Thus, hcf (123,456) = 3 , the second last remainder.

Exercise 14 Use Euclidean Algorithm to find hcf (889,2159) .

Now, let’s look at some other applications of Euclidean Algorithm.

Result 15 Let a and b be any integers. Then =


a × b hcf (a, b ) × lcm(a, b ) .

Thus, we can use Euclidean Algorithm to find the hcf of two numbers first before
finding their lcm using Result 15.

Page 1-6
Primary Math Master Class Workshop: Euclidean Algorithm

Exercise 16 Find lcm(297,495) .

Exercise 17 Use the Euclidean Algorithm to find hcf ( 95,417 )

Reflections 18
(i) Does the Euclidean Algorithm involve more steps if we use large numbers?

(ii) Is the Euclidean Algorithm always more efficient than the other methods:
listing factors, prime factorization, synthetic division?

Page 1-7
Primary Math Master Class Workshop: Euclidean Algorithm

Extended Euclidean Algorithm


We can apply the Extended Euclidean Algorithm to solve the decanting problem.

Problem Given a 3-litres jug and a 5-litres jug, how do we measure 1 litre of water
using just the two jugs? We only know the capacities of the jugs. There are no
additional markings on the jugs for us to measure 1 litre.

Solution
Using Euclidean Algorithm to find hcf ( 3,5 ) :

5 = 3 × 1 + 2........[1]
3 = 2 × 1 + 1.........[2]
1 =1× 2 + 0.........[3]

Now use [1], [2], [3] to get other relationships (this is called the Extended Euclidean
Algorithm):
From [2], 1 = 3 − 2 × 1.
Then use [1] to write 2 in terms of 3 and 5 (the jugs that you have):
1 = 3 − ( 5 − 3 × 1) × 1
1 = 3 × ( 2 ) + 5 × ( −1)

Now, the numbers inside the brackets give us a hint of how many times we pour
water into (+) the jug or out of (-) the jug. Initially, the 2 jugs are empty.
Step Action Amount of water Amount of water
in 3-litre jug in 5-litre jug
1 Fill up the 3-litre jug with water. (+) 3 litres 0 litres
2 Pour all the water from the 3-litre jug to 0 litres 3 litres
the 5-litre jug. Transfer costs nothing.
3 Fill up the 3-litre jug with water. (+) 3 litres 3 litres
4 Pour water from the 3-litre jug to the 5- 1 litre 5 litres
litre jug until the 5-litre jug is full.
Transfer costs nothing.
5 Pour away all the water from the 5-litre 1 litre 0 litres
jug. (-)
Now, you have 1 litre of water (in the 3-litre jug).

Page 1-8
Primary Math Master Class Workshop: Euclidean Algorithm

Exercise 19 Given a 13-litres jug and a 17-litres jug, how do we measure 1 litre of
water using just the two jugs? We only know the capacities of the jugs. There are no
additional markings on the jugs for us to measure 1 litre.

Is there another way to measure 1 litre of water using just the two jugs? Compare
your answer with your friend’s. If your answers differ, copy your friend’s answer
below.

Page 1-9
Primary Math Master Class Workshop: Euclidean Algorithm

To solve Exercise 19, we need to find integers x and y such that 13 x + 17 y =


1,
which is an example of a Linear Diophantine equation. Your working above shows
= =
that x ____, y ____ . So, you have found a particular solution. Can you find all
=
other solutions? For example, =
x ____, y ____ will also work. When we try to find
all other solutions, we are said to be finding the general solution of the Linear
Diophantine equation.

Solving Linear Diophantine equations


Let’s consider the Linear Diophantine equation 13 x + 17 y =
1.
Let=x x=
1, y y1 be a solution. Then 13 x1 + 17 y1 =
1.

=
Let x x=
2, y y 2 be another solution. Then _________________________ .

Now, 13 x1 + 17 y1 = 13 x2 + 17 y 2 . Why? ________________________________

So, 13 x1 − 13 x2 = 17 y 2 − 17 y1

13 ( x1 − x2 =
) 17 ( y 2 − y1 )
Since hcf (13,17 ) = 1, we can use Euclid’s Lemma to deduce that 13 | ( y 2 − y1 ) , i.e.

y 2 − y1 =
13k , where k is an integer. So, y=
2 y1 + 13k .

Similarly, since hcf (13,17 ) = 1, we can use Euclid’s Lemma to deduce that

17 | ( x1 − x2 ) , i.e. x1 − x2 =
17m , where m is an integer. So, x=
2 x1 − 17m .

1, we deduce that 13 ( x1 − 17m ) + 17 ( y1 + 13k ) =


Since 13 x2 + 17 y 2 = 1.

So,
13 x1 + 17 y1 − 13 × 17m + 17 × 13k =
1
1 − 13 × 17m + 17 × 13k =
1
17 × 13k =13 × 17m
k =m
Thus, given a particular solution=x x=
1, y =
y1 , the general solution is x x=
2, y y2 ,

where x=
2 x1 − 17k and y=
2 y1 + 13k and k is an integer. Different values of k give

rise to different solutions.

Page 1-10
Primary Math Master Class Workshop: Euclidean Algorithm

Now, find out which value of k gives rise to your friend’s answer (if different from
yours).

We can borrow the aforementioned idea to prove a more general result.


Result 20 Let a, b, c be integers. Let d = hcf ( a, b ) .

The Linear Diophantine equation ax + by =


c has solutions if and only if d | c .
When ax + by =
c has solutions, it has infinitely many solutions. Given a particular
b
solution=x x=
1, y =
y1 , the general solution is x x=
2, y y 2 , where x=
2 x1 + k,
d
a
y=
2 y1 − k , k is an integer. [So, different values of k give rise to different solutions.]
d
Note: We usually find a particular solution with the help of Extended Euclidean
Algorithm.

Exercise 21
Determine whether each of the following Linear Diophantine equations has solutions.
If it has solutions, find the general solution.
(a) 6 x + 9 y =
14
(b) 6 x + 9 y =
21

Page 1-11
Primary Math Master Class Workshop: Euclidean Algorithm

Exercise 22
A zoo charges $10 for adult admissions and $8 for children admissions. On a
particular evening, the total receipts were $82. Given that there were more children
admissions than adult admissions, how many people visited the zoo?

Page 1-12

You might also like