0% found this document useful (0 votes)
66 views61 pages

11 Euclids-Algorithm

Algorithm lesson

Uploaded by

ShelaRamos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views61 pages

11 Euclids-Algorithm

Algorithm lesson

Uploaded by

ShelaRamos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

SCHOLAR Study Guide

CfE Advanced Higher Mathematics


Course materials
Topic 11: Euclid’s algorithm

Authored by:
Fiona Withey (Stirling High School)
Karen Withey (Stirling High School)

Reviewed by:
Margaret Ferguson

Previously authored by:


Jane S Paterson
Dorothy A Watson

Heriot-Watt University
Edinburgh EH14 4AS, United Kingdom.
First published 2016 by Heriot-Watt University.
This edition published in 2017 by Heriot-Watt University SCHOLAR.
Copyright © 2017 SCHOLAR Forum.
Members of the SCHOLAR Forum may reproduce this publication in whole or in part for educational
purposes within their establishment providing that no profit accrues at any stage, Any other use of the
materials is governed by the general copyright statement that follows.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted
in any form or by any means, without written permission from the publisher.
Heriot-Watt University accepts no responsibility or liability whatsoever with regard to the information
contained in this study guide.

Distributed by the SCHOLAR Forum.


SCHOLAR Study Guide Course Materials: CfE Advanced Higher Mathematics
1. CfE Advanced Higher Mathematics Course Code: C747 77
Acknowledgements
Thanks are due to the members of Heriot-Watt University's SCHOLAR team who planned and created these
materials, and to the many colleagues who reviewed the content.
We would like to acknowledge the assistance of the education authorities, colleges, teachers and students
who contributed to the SCHOLAR programme and who evaluated these materials.
Grateful acknowledgement is made for permission to use the following material in the SCHOLAR
programme:
The Scottish Qualifications Authority for permission to use Past Papers assessments.
The Scottish Government for financial support.
The content of this Study Guide is aligned to the Scottish Qualifications Authority (SQA) curriculum.

All brand names, product names, logos and related devices are used for identification purposes only and are
trademarks, registered trademarks or service marks of their respective holders.
1

Topic 11

Euclid's algorithm

Contents
11.1 Looking back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
11.2 The division algorithm and number bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
11.2.1 Divisibility rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
11.2.2 The division algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
11.2.3 Number bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
11.3 The Euclidean algorithm and its applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
11.3.1 The Euclidean algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
11.3.2 The GCD as a linear combination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
11.4 Learning points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
11.5 Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
11.6 Extended information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
11.7 End of topic test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2 TOPIC 11. EUCLID'S ALGORITHM

Learning objective

By the end of this topic, you should be able to:

• state and use the divisibility rules for integers;


• define the division algorithm;
• use the division algorithm to identify a quotient and remainder when given a divisor;
• convert a number from a base other than 10 into base 10;
• convert a number from base 10 into other bases such as binary, octal and hexadecimal;
• use the Euclidean algorithm to find the greatest common divisor of two numbers;
• write two integers as a linear combination of their greatest common divisor.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 3

11.1 Looking back


Pre-requisites from Advanced Higher
You should have covered the following in the Partial fractions topic. If you need to reinforce your
learning go back and study this topic.
Algebraic long division

You should have a working knowledge of some definitions associated with division:

• the dividend in a long division calculation is the expression which is being divided - as a fraction
it is the numerator;
• the divisor is the expression which is doing the dividing - as a fraction it is the denominator;
• the quotient is the integer answer to the division, but not including any remainder;
• the remainder is the amount left over after dividing.

You should have covered the following in the Matrices topic. If you need to reinforce your learning
go back and study this topic.
Gaussian elimination

• Gaussian elimination is using elementary row operations to transform an augmented matrix


into an upper triangular form. Back substitution is then used to find the values of the unknown
variables.
• Gauss-Jordan elimination is using elementary row operations to transform an augmented
matrix into an identity matrix. From here the values of the unknown variables can be found
without back substitution.

Determinants

• The determinant of a matrix is a value representing sums and products of a square matrix.
• The determinant only exists for a square matrix. It is a number, not a matrix.
 
a b
• If A = , then the determinant of the 2 × 2 matrix A is given by det(A) =
c d

© H ERIOT-WATT U NIVERSITY
4 TOPIC 11. EUCLID'S ALGORITHM

 
 a b 
 
  = ad − bc
 c d 
⎛ ⎞
a b c
⎜ ⎟
• If A = ⎝ d e f ⎠, then the determinant of the 3 × 3 matrix A is given by det(A) =
g h i
 
 a b c 

 
 d e f  = a(ei − f h) − b(di − f g) + c(dh − ge)
 
 g h i 
• An alternative method of working out the determinant of a 3 × 3 matrix is as follows:

1. Make two copies of the matrix side by side.


2. For each entry in the top row of the first matrix multiply down the diagonal to the right.
3. For each entry in the top row of the second copy of the matrix, multiply down the diagonal
to the left and add a minus sign.
det = −af h − bdi − ceg + aei + bf g + cdh

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 5

11.2 The division algorithm and number bases


This section begins by stating the divisibility rules for integers which are multiples of 2 to 10. These
will be useful rules to know throughout this topic, especially if you do not have a calculator handy.
It will then move onto explaining the division algorithm and then end with a section on number
bases.

11.2.1 Divisibility rules


The following divisibility rules for integers are useful to make quick checks on wether a number is
divisible by the integers 2 to 10.

An integer N is divisible by:


2 if the last digit is even;
3 if the sum of its digits is divisible by 3;
4 if the number formed by the last two digits is divisible by 4;
5 if the last digit is 5 or 0;
6 if it is divisible by 2 and 3;
if the number formed by removing the last digit and subsequently subtracting twice
7
the last digit is divisible by 7;
8 if the number formed by the last three digits is divisible by 8;
9 if the sum of its digits is divisible by 9;
10 if it ends in 0.

11.2.2 The division algorithm


At this point it is convenient to introduce an extra piece of symbolism. Consider the equation
6 = 3 × 2. A less precise way of stating this could be '2 divides 6' or '3 divides 6'. For ease this is
commonly written as 2|6 or 3|6.

Key point

a|b means a divides into b

This symbolism not only is a neat shorthand way of expressing division, but also has another
advantage over the words: when written in this form, a|b, then it is assumed that a = 0 provided
that b = 0. If, in fact, a does not divide b, this can be shown as a  b

Key point

a  b means a does not divide into b

Obviously, in the integers 3  7, but to cope with this, most people are taught at an early age to write
this sum with a remainder such that 7 = 2 × 3 + 1
In general terms, if there are two integers a and b (such that a > b) where b  a, then this can be
written as a = qb + r where q and r are also integers. It is this type of division which forms the

© H ERIOT-WATT U NIVERSITY
6 TOPIC 11. EUCLID'S ALGORITHM

basis of the division algorithm.

There are two forms of the algorithm which differ only in the condition placed on the remainder r.

The original form of the division algorithm has the condition 0 ≤ r < b where b is the divisor.

The general form of the division algorithm replaces this condition with 0 ≤ r < |b| and is given in
the definition which follows.
Key point

If a and b are integers, b = 0, then there are unique integers q and r such that a = qb + r
where 0  r  |b|.
As in any division, q is the quotient and r is the remainder.

Example
Problem:
Find two integers q and r such that a = qb + r when a = 3465 and b = 420
Solution:
3465
Start with ab : 420 = 8 r = 105
We have 3465 = 8.420 + 105
so q = 8 which is an integer and r = 105 which is an integer less than 420.

Top tip

Note the convention of expressing the calculation using a dot. This is an important and
useful approach to adopt with both the division and the Euclidean algorithm.

Examples

1. Problem:
Find two integers q and r such that a = qb + r when a = 33 and b = 4.
Solution:
33
Start with ab : 4 =8 r=1
We have 33 = 8.4 + 1
so q = 8 and r = 1.
...............................................

2. Problem:
Find two integers q and r such that a = qb + r when a = − 29 and b = 6.
Solution:
−29
Start with ab : 6 = −4 r = −5

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 7

We have −29 = − 4.6 − 5


So q = − 4 and r = − 5.
But the remainder must be positive by definition of the division algorithm. Therefore, we need
to have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 5
−5.6 = − 30 so to make it up to -29 we need to add on 1.
We have −29 = − 5.6 + 1
So q = − 5 and r = 1.

At first glance, the subtleties of the division algorithm may go unnoticed.

In the example when a = 33 and b = 4, note that 33 = 7.4 + 5 is not a solution in keeping with
the division algorithm since in this case r > b, i.e. 5 > 4.

In the example when a = − 29 and b = 6, note that r is positive in keeping with the division
algorithm so −29 = − 4.6 − 5 is not a solution.

There is a proof shown in the section headed Proofs near the end of this topic which justifies the
division algorithm.
For a brief look at the proof go to the extra study activity now.

Proof 1: The division algorithm

The proof of the division algorithm is based on the 'well ordering principle' which states that
every nonempty set S of non-negative integers contains a least element. The proof is shown
for the original form with 0 ≤ r < b.
Let S be the set {a − xb such that x ∈ Z and a − xb ≥ 0}

The steps in the proof are as follows:

1. Show that the set S is nonempty.

2. Show that S contains a least element.

3. Show that r < b.

4. Show the uniqueness of q and r.

1. To show that S is a nonempty set, we must show that it contains the elements a − xb
such that x ∈ Z and a − xb ≥ 0. We do this in the following way:
By the condition on b in the definition of the division algorithm b ≥ 1.
Multiplying both sides by |a|, to ensure that the answer is positive, we get:

© H ERIOT-WATT U NIVERSITY
8 TOPIC 11. EUCLID'S ALGORITHM

|a| b  |a|
Now add a to both sides:
a + |a| b  a + |a|
a − (− |a|) b  a + |a|
By letting x = − |a| we then have:
a − xb  a + |a|
Since a ∈ Z, then it can be positive or negative. The minimum value of a + |a| is
therefore 0 and so we can write:
a − xb ≥ 0.
Therefore, if x = −|a|, then a − xb ∈ S.

2. Show that S contains a least element:


by the well ordering principle, since S is nonempty, it contains a least element, say r,
such that r = a − qb for some integer q and r ≥ 0

3. To prove that r < b we use proof by contradiction. We will see this type of proof in the
topic Methods of Proof. We start by setting up a false assumption then work through
logical steps to show that a contradiction happens. This is done as follows:
Assume that r ≥ b
From the division algorithm r = a − qb we can also say that r = a − (q + 1)b so
the RHS becomes:
a − qb − b
From the division algorithm we know that r = a − qb, so substituting in the previous
expression we get:
r − b
We can say that r − b ≥ 0 based on our assumption that r ≥ b, but r − b < r
which contradicts the fact that r is chosen as the least element in S (from step 2) so the
assumption that r ≥ b is false and the original conjecture r < b is true.

4. For this proof, we start by assuming that there are two possible values for q and r. By
following logical steps we will then show that the two values of q are equal and the two
values of r are equal.
Suppose that a = bq 1 + r1 and a = bq2 + r2 with the conditions 0 ≤ r1 < b and
0 ≤ r2 < b.
Since both expressions are equal to a we can write: bq 1 + r1 = bq2 + r2
Collecting like terms and factorising we get:
bq1 − bq2 = r2 − r1
b (q1 − q2 ) = r2 − r1
The RHS is therefore a multiple of b, but the conditions on r 1 and r2 state that they must
be less than b and greater than or equal to zero.
The maximum value that r 1 and r2 can take individually is b and their minimum values
can be zero.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 9

Therefore the maximum value of r 2 − r1 occurs when r2 is as large as possible, i.e.


r2 < b and r1 is as small as possible, i.e r1 = 0. This gives r2 − r1 < b.
The minimum value of r 2 − r1 occurs when r2 is as small as possible, i.e. r2 = 0 and
r1 is as large as possible, i.e. r1 < b. This gives −b < r2 − r1 .
Putting these both together gives −b < r 2 − r1 < b
The only multiple of b between −b and b is zero.
Hence,
r2 − r1 = 0 ⇒ r2 = r1
and
b(q1 − q2 ) = 0 ⇒ q1 = q2 (since b = 0).

It may not be apparent, but the division algorithm is used in some form in many of the proofs in the
topic Methods of proof. The application of the algorithm produces the integer forms such as 2k for
an even integer and 2k + 1 for an odd integer.

It is the condition 0 ≤ r < |b| that is used to great effect in determining the form that a particular
number can take.

Suppose that b = 4, then, in the equation a = qb + r, the division algorithm shows that a will
have one of the following forms:

• 4k where r = 0 with q = k
• 4k + 1 where r = 1
• 4k + 2 where r = 2
• 4k + 3 where r = 3

In all cases, r satisfies the condition 0 ≤ r < |b|.

The division algorithm practice Go online

Q1: Determine all of the even forms of a number on division by 8.

These types of integer forms are the basis of many proofs.


...............................................

Q2: Find two integers q and r such that a = qb + r when a = 2584 and b = 158.
...............................................

Q3: Find two integers q and r such that a = qb + r when a = − 148 and b = 13.
(Be careful here to recall that the remainder must be positive according to the division
algorithm.)
...............................................

© H ERIOT-WATT U NIVERSITY
10 TOPIC 11. EUCLID'S ALGORITHM

Q4: Find two integers q and r such that a = qb + r when a = − 452 and b = 11.
...............................................

Q5: Find two integers q and r such that a = qb + r when a = − 168 and b = 23.
...............................................

Q6: Find two integers q and r such that a = qb + r when a = 235 and b = − 19.

The division algorithm exercise Go online

Q7: Using the division algorithm, find q and r such that a = qb + r where a = − 42 and
b = 5.
...............................................

Q8: Using the division algorithm, find q and r such that a = qb + r where a = 25 and
b = − 7.
...............................................

Q9: Using the division algorithm, find q and r such that a = qb + r where a = 14 and
b = − 9.
...............................................

Q10: Using the division algorithm, find q and r such that a = qb + r where a = − 1 and
b = 3.
...............................................

Q11: Using the division algorithm, find q and r such that a = qb + r where a = 4 and
b = 9.
...............................................

Q12: Using the division algorithm, find q and r such that a = qb + r where a = − 12 and
b = 3.

11.2.3 Number bases


The division algorithm is a simple method used to convert integers to different number bases. The
standard number base used in mathematics is 10, that is, the place values of a number are powers
of 10. The decimal system, as it is known, has the structure as shown in the following example for
the number 25367:
104 103 102 101 100
↓ ↓ ↓ ↓ ↓
2 5 3 6 7

2.104 + 5.103 + 3.102 + 6.101 + 7.100


= 2.10000 + 5.1000 + 3.100 + 6.10 + 7.1
= 2536710

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 11

A number can be converted and expressed in a different number system using any integer as a
number base, but three of the most useful are the bases 2, 8 and 16. These are called binary, octal
and hexadecimal, respectively, and are used extensively in subjects such as computing and
electronics.
Binary

In the decimal number system, there are ten digits: 0 to 9. In binary, which has a base of 2, there
are just two digits: 0 and 1. The place values in a binary system are all powers of 2 and an
example showing these place values can be constructed for the binary number 11010 2:
24 23 22 21 20
↓ ↓ ↓ ↓ ↓
1 1 0 1 0

The illustration above and calculation below shows how easy it is to find the decimal form of a
binary number.

1.24 + 1.23 + 0.22 + 1.21 + 0.20


= 1.16 + 1.8 + 0.4 + 1.2 + 0.1
= 26

The division algorithm is used to find the binary form from the decimal form and is best described
by an example.

Example
Problem:
Convert 30 into a binary number.
Solution:
Use the algorithm repeatedly for a = qb + r
In the first case, a = 30 and b = 2 (for binary), then a = 15 while b remains 2, and so on
until the algorithm can be taken no further. The bold highlighting shows how each value for a
is determined from the previous line of working.
30 = 15.2 + 0
15 = 7.2 + 1
7 = 3.2 + 1
3 = 1.2 + 1
1 = 0.2 + 1
The binary number is taken directly from the remainders in this calculation by reading them
off upwards from the last line, giving 11110 2.
Note that, unless it is known that we are working in binary, 11110 could look like a number in
base 10. To eliminate confusion, we add a subscript to the end of the number to indicate the
base.

© H ERIOT-WATT U NIVERSITY
12 TOPIC 11. EUCLID'S ALGORITHM

Octal

This is just as straightforward but uses the powers of 8 as place values. The octal system only uses
the eight integers 0 to 7.

Example
Problem:
Convert the number 53467 into octal form.
Solution:
In this case, the equation a = qb + r starts with a = 53467 and has b = 8 throughout.
53467 = 6683.8 + 3
6683 = 835.8 + 3
835 = 104.8 + 3
104 = 13.8 + 0
13 = 1.8 + 5
1 = 0.8 + 1
The bold highlighting shows how each value for a is determined from the previous line of
working.
Again, the octal number is taken directly from the remainders in the calculation by reading
them off upwards from the last line, giving 150333 8.
This can be checked in reverse as 3.80 + 3.81 + 3.82 + 5.84 + 1.85 = 5346710 .
Note that, for our answer above, unless it is known that we are working in base 8, 150333
could look like a number in base 10. To eliminate confusion, we add a subscript to the end of
the number to indicate the base.

Hexadecimal

This system uses base 16 and has sixteen 'digits'. Since each digit can only occupy one place
value, a slight modification is needed. In this case, the system uses integers 0 to 9 and then A for
10, B for 11, C for 12, D for 13, E for 14 and F for 15.

Example
Problem:
Find the hexadecimal form of the number 298047.
Solution:
Repeated application of the division algorithm starting with a = 298047 and using
b = 16 throughout gives:

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 13

298047 = 18627.16 + 15 (note: 15 ≡ F)


18627 = 1164.16 + 3
1164 = 72.16 + 12 (note: 12 ≡ C)
72 = 4.16 + 8
4 = 0.16 + 4
The bold highlighting shows how each value for a is determined from the previous line of
working.
The hexadecimal number taken from the remainders by reading them off upwards from the
last line is 48C3F16.
Note that, for our answer above, it is fairly clear that we are working in base 16 because of
the use of letters in the number, but to eliminate any possible confusion we add a subscript
to the end of the number to indicate the base.

"Mathematics is the queen of sciences and number theory is the queen of mathematics."
Carl Gauss (1777 - 1855)

Number bases practice Go online

Q13: What is the binary number 11101 2 in base 10?


24 23 22 21 20
↓ ↓ ↓ ↓ ↓
1 1 1 0 1
...............................................

Q14: What is the octal number 73201 8 in base 10?


84 83 82 81 80
↓ ↓ ↓ ↓ ↓
7 3 2 0 1
...............................................

Q15: What is the hexadecimal number F1EA3 16 in base 10?


164 163 162 161 160
↓ ↓ ↓ ↓ ↓
F 1 E A 3

The following table should be used to answer the remaining questions.


104 103 102 101 100
↓ ↓ ↓ ↓ ↓
2 5 3 8 4

© H ERIOT-WATT U NIVERSITY
14 TOPIC 11. EUCLID'S ALGORITHM

Q16: What is the base 10 number above in binary?


...............................................

Q17: What is the base 10 number above in octal?


...............................................

Q18: What is the base 10 number above in hexadecimal?

Number bases exercise Go online

This is an interesting exercise on converting numbers to bases other than decimal.

Q19: Convert 332 into a binary number.


...............................................

Q20: Convert 501 into a binary number.


...............................................

Q21: Convert 43 into a binary number.


...............................................

Q22: Convert 63 into a binary number.


...............................................

Q23: Find the octal form of 347.


...............................................

Q24: Find the octal form of 2924.


...............................................

Q25: Find the octal form of 3012.


...............................................

Q26: Find the octal form of 534.


...............................................

Q27: Find the hexadecimal equivalent number to 4014.


...............................................

Q28: Find the hexadecimal equivalent number to 364.


...............................................

Q29: Find the hexadecimal equivalent number to 2179.


...............................................

Q30: Find the hexadecimal equivalent number to 5034.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 15

11.3 The Euclidean algorithm and its applications


In the last section the definition of the division algorithm gives expressions of the form a = qb + r
Consider what happens when r = 0
In this case, the division algorithm leads to a definition.

Key point

An integer b is said to be divisible by a, that is a|b if b = ac for some integer c. So a is a


divisor of b.

Suppose that there is an integer d such that d|a and d|b for two integers a and b, one non-zero. In
this case, d is a common divisor of a and b. An extra condition gives a definition for the greatest
common divisor.
Key point

Greatest Common Divisor


The greatest common divisor of two integers a and b, where at least one is non-zero, denoted
gcd(a, b) is the positive integer d such that:

• d|a and d|b;


• if c|a and c|b then c ≤ d

The greatest common divisor is also well known as the highest common factor (hcf).

Example
Problem:
Find gcd(42, 78).
Solution:
Positive divisors of 42 are 1, 2, 3, 6, 7, 14, 21, 42.
Positive divisors of 78 are 1, 2, 3, 6, 13, 26, 39, 78.
The common divisors are 1, 2, 3, 6 of which 6 is the greatest.
gcd(42, 78) = 6

A particular case occurs when, for two integers a and b, gcd(a, b) = 1

Key point

Relatively Prime
The integers a and b, where at least one is non-zero, are relatively prime when gcd(a, b) = 1

© H ERIOT-WATT U NIVERSITY
16 TOPIC 11. EUCLID'S ALGORITHM

Example
Problem:
Show that 2210 and 399 are relatively prime.
Solution:
The factors of 2210 are 1, 2, 5, 10, 13, 17, 26, 34, 65, 85, 130, 170, 221, 442, 1105, 2210.
The factors of 399 are 1, 3, 7, 19, 21, 57, 133, 399.
The only common factor is 1.
gcd(2210, 399) = 1
By definition, the integers are relatively prime.

It would be tedious to take large integers and search for their factors, as the last question
demonstrates. In fact the division algorithm again plays its part in producing another famous
algorithm to make this task much easier.

11.3.1 The Euclidean algorithm


This algorithm is very similar to the calculation required for the change of number base except that,
at each step, the value of b also changes. By repeated use of the division algorithm, the calculation
is subsequently reduced to give the greatest common divisor in the final step. An example will help
to demonstrate this.

Examples

1. Problem:
Find gcd(6, 16).
Solution:
Using the expression a1 = qb1 + r1 , let a1 be the larger number, in this case 16, and b 1 the
smaller number, in this case 6: 16 = q.6 + r1
Pick values for q and r1 to satisfy the expression, e.g. q = 2 and r1 = 4: 16 = 2.6 + 4

Use the division algorithm again, where a 1 = 6 and b1 = 4: 6 = 1.4 + 2

Use the division algorithm again, where a 1 = 4 and b1 = 2: 4 = 2.2 + 0

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 17

The remainder is now 0 so we stop.


gcd(6, 16) = 2
The following diagram demonstrates how 16 (top) and 6 (bottom) have been split up using
the highest common factor of 2.

...............................................

2. Problem:
Find gcd(140, 252).
Solution:
Using the expression a1 = qb1 + r1 let a1 be the larger number:
a1 = 252 and then b1 = 140
Use the division algorithm to obtain: 252 = 1.140 + 112
At this stage a2 becomes 140 and b 2 becomes 112 and the next step gives: 140 = 1.112 + 28
The process continues: 112 = 4.28 + 0
Once r = 0 after i steps, the algorithm stops and the last value of b i gives the greatest
common divisor of the two numbers.
In this case gcd(140, 252) = 28

Here is a diagram indicating the steps in the algorithm for the last example.
To find gcd(140, 252) using the Euclidean algorithm:

It is common to write the gcd of two numbers as gcd(140, 252) = 28 as in the last example.

© H ERIOT-WATT U NIVERSITY
18 TOPIC 11. EUCLID'S ALGORITHM

Example
Problem:
Find gcd(1980, 3696).
Solution:
Let the larger number be a = 3696 and let b = 1980. Now use the division algorithm to give:
3696 = 1.1980 + 1716
1980 = 1.1716 + 264
1716 = 6.264 + 132
264 = 2.132 + 0
The greatest common divisor (or highest common factor) of 3696 and 1980 is 132, i.e.
gcd(1980, 3696) = 132.

An interesting use of this algorithm is to reduce fractions.

Example
Problem:
19712
Simplify the fraction 55040

Solution:
Use the Euclidean algorithm to find gcd(19712, 55040):
55040 = 2.19712 + 15616
19712 = 1.15616 + 4096
15616 = 3.4096 + 3328
4096 = 1.3328 + 768
3328 = 4.768 + 256
768 = 3.256 + 0
Thus, the gcd(19712, 55040) = 256 so now divide both numerator and denominator by 256
77
to give the fully simplified fraction as 215

It is possible, in a few simple steps, to use a graphics calculator to perform this algorithm and
calculate the gcd. The following command steps to work out the gcd are for a TI-83 Plus graphic
calculator.

1. Press MATH to access the maths menu.


2. Press the right arrow key to select the NUM submenu.
3. Press 9 to select gcd or use the down arrow key.
4. The command syntax takes the following form: gcd(value 1, value 2).

Fibonacci numbers
The Fibonacci sequence, mentioned in the topic about Sequences and series, produces some
fascinating results in this topic.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 19

Recall that the sequence is defined by u n + 2 = un + 1 + un where u1 = 1 and u2 = 1. The


sequence is: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, . . .
It can be shown that gcd(u n , un + 1 ) = 1 for all n ≥ 1, hence successive Fibonacci numbers are
relatively prime.
There is a proof in the proofs section which justifies that successive Fibonacci numbers are relatively
prime. This is not required to be reproduced for exam purposes, simply for your interest.
For a brief look at the proof go to the extra study activity now.

Proof 2: Successive Fibonacci numbers are relatively prime

To prove this we will use proof by contradiction.


Assume that consecutive Fibonacci numbers u n − 1 and un are relatively prime but that
un and un + 1 have some common factor d > 1.
By the definition of Fibonacci numbers, u n + 1 = un + un − 1 .
Rearranging gives un − 1 = un + 1 − un .
Since d divides both un andun + 1 , then it also divides un − 1 . (This is a divisibility rule).
This means that un and un − 1 have a common factor of d > 1, so they cannot be relatively
prime.
This contradicts our assumption.
Our assumption that un and un + 1 have some common factor d > 1 is therefore false.
Hence, un and un + 1 must have gcd(un , un + 1 ) = 1 for all n ≥ 1 and are therefore
relatively prime.

Now consider non-successive Fibonacci numbers by looking at this example.

Example
Problem:
Find gcd(610, 8) and gcd(610, 55)
Solution:
610 = 76.8 + 2 610 = 11.55 + 5
8 = 4.2 + 0 55 = 11.5 + 0
gcd (610, 8) = 2 gcd (610, 55) = 5

The example used the Fibonacci numbers 8, 55 and 610. The answers were also the Fibonacci
numbers 2 and 5 and, in general, it can be proved that the greatest common divisor of two
Fibonacci numbers is in fact another Fibonacci number. This result can be taken further.

The question first asked for gcd(610, 8). These are the Fibonacci numbers u 15 and u6 and the
answer of a greatest common divisor of 2 is the Fibonacci number u 3 .

Thus, gcd(u15 , u6 ) = u3 and this leads to a very useful theorem.

© H ERIOT-WATT U NIVERSITY
20 TOPIC 11. EUCLID'S ALGORITHM

Key point

The greatest common divisor of two Fibonacci numbers is also a Fibonacci number such
that gcd(un , um ) = ud where gcd(n, m) = d

Example
Problem:
Find gcd(987, 144)
Solution:
987 = u16 and 144 = u12
But gcd(16, 12) = 4 and so gcd(987, 144) = u 4 = 3

The Euclidean algorithm can be used to check that gcd(987, 144) = 3


There is a proof in the proofs section which justifies the Euclidean algorithm. This is not required to
be reproduced for exam purposes, simply for your interest.
For a brief look at the proof go to the extra study activity now.

Proof 3: The Euclidean algorithm

Investigate the proposition that every positive integer can be expressed as a sum of Fibonacci
numbers with none used more than once.
(You are not expected to learn the proof for this but, if you choose, try to follow the steps.)
To investigate, list the first 10 Fibonacci numbers and work out the sums needed to obtain the
first 13 positive integers without repetitive use of the Fibonacci numbers.
The first 10 Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.
Sums to get the first 13 positive integers without repetition of Fibonacci numbers:

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 21

1=1
2=2
3=3
4 =3 + 1
5 =5
6=5+1
7=5+2
8=8
9=8+1
10 = 8 + 2
11 = 8 + 3
12 = 8 + 3 + 1
13 = 13
There are other representations for the sums of Fibonacci numbers,
e.g. 6 = 5 + 1 or 6 = 3 + 2 + 1
Theorem
Every positive integer can be expressed as a sum of Fibonacci numbers with none used more
than once.
We will prove this using strong mathematical induction, not weak mathematical induction
as you will learn in the topic Methods of Proof.
Let Fm represent a Fibonacci number for m ≥ 1, m ∈ Z and n ∈ Z + .

The statement is clearly true for the integers n = 1, 2 and 3 since,


• The first Fibonacci number is F1 = 1

1. • The third Fibonacci number is F 3 = 2


• The fourth Fibonacci number is F 4 = 3

i.e. the first three positive integers are the sum of single Fibonacci numbers.

© H ERIOT-WATT U NIVERSITY
22 TOPIC 11. EUCLID'S ALGORITHM

Suppose that the conjecture is true for all n ≤ k (this is the induction hypothesis for
strong induction, while n = k is used for weak induction).
i.e. we have assumed that any integer ≤ k can be written as the sum of Fibonacci
numbers.
We will prove that the statement is true for n = k + 1.
If k + 1 = Fm for some m, then it is trivially correct.
i.e. if the integer k + 1 is already a Fibonacci number, it is automatically the sum of a
single Fibonacci number. This was exemplified in step 1.
In other cases we find the m such that Fm < k + 1 < Fm + 1 .
Now subtract Fm from each part of the inequality:
2. 0 <k + 1 − Fm < Fm+1 − Fm
0 <k + 1 − Fm < Fm−1
Let q = k + 1 − Fm , then we can write q as the sum of non-consecutive Fibonacci
numbers because k + 1 − Fm < k + 1 which means that q < k + 1.
i.e. q is an integer less than k + 1 which means that q ≤ k and we stated as an
assumption, at the beginning of step 2, that the conjecture was true for all integers n ≤ k.
We also note that this sum does not contain F m − 1 because from the inequality above
q = k + 1 − Fm < Fm − 1 .
So if we add Fm to the sum of non-consecutive Fibonacci numbers for q we have a non-
consecutive sum of Fibonacci numbers for k + 1 as well, i.e. k + 1 = q + Fm , and the
statement is true for n = k + 1.

Therefore, by strong mathematical induction, we have proven that every positive integer
n can be written as the sum of one or more distinct Fibonacci numbers.

The Euclidean algorithm practice Go online

Q31: Use the Euclidean algorithm to find gcd(299, 1365).


...............................................

Q32: What is the highest common factor of 5187 and 760?


...............................................

Q33: Use the Euclidean algorithm to show that 10465 and 5643 are relatively prime.
...............................................

Q34: Use the Euclidean algorithm to find gcd(3024, 5184).


...............................................
372
Q35: Reduce the fraction 4340 to its simplest form.
...............................................
19327
Q36: Using the Euclidean algorithm, simplify the fraction 25602 .

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 23

The Euclidean algorithm exercise Go online

This is a simple exercise to give practice in finding the greatest common divisor of two positive
integers.

Q37: Use the Euclidean algorithm to find the greatest common divisor of the integers 943
and 779.
...............................................
3763
Q38: Use the Euclidean algorithm to simplify the fraction 5141
...............................................
1349
Q39: Use the Euclidean algorithm to simplify the fraction 3053
...............................................
3276
Q40: Use the Euclidean algorithm to simplify the fraction 4056

11.3.2 The GCD as a linear combination


Having used the Euclidean algorithm to find the gcd of two integers, it is possible to take the
algorithm and retrace the steps taken to arrive at a linear combination of the two integers which
equals the gcd.

Example
Problem:
Find gcd(2695, 1260) as a linear combination of 2695 and 1260.
Solution:
Our target is to find an answer that takes the form gcd(2695, 1260) = 2695x + 1260y where
gcd(2695, 1260), x and y are integers.
First, we must use the Euclidean algorithm to obtain the gcd(2695, 1260).
2695 = 2.1260 + 175
1260 = 7.175 + 35
175 = 5.35 + 0
Therefore, gcd(2695, 1260) = 35
To obtain the linear combination and work out the values of x and y we now work backwards
in the following way.
Take the second last line of working from the Euclidean algorithm and rearrange for the
remainder 35. This means that straight away we have established the LHS of our desired
result.
1260 = 7.175 + 35 → 35 = 1260 − 7.175
Now, go back one more line and take the first line of the Euclidean algorithm and rearrange

© H ERIOT-WATT U NIVERSITY
24 TOPIC 11. EUCLID'S ALGORITHM

for the remainder 175.


2695 = 2.1260 + 175 → 175 = 2695 − 2.1260
Take this rearrangement and substitute into 35 = 1260 − 7.175
35 = 1260 − 7.175
35 = 1260 − 7. (2695 − 2.1260)
The RHS now involves the numbers 2695 and 1260, which is what we wanted. Expand the
bracket and simplify by collecting terms involving 2695 and 1260 together.
35 = 1260 − 7.2695 + 14.1260
35 = − 7.2695 + 15.1260
This is now in the from where:
gcd(2695, 1260) = 35
x = −7
y = 15

Key point

To find gcd(a, b) as a linear combination of a and b:

1. Use the Euclidean algorithm to find gcd(a, b).

2. Take the second last equation of the Euclidean algorithm and rearrange for gcd(a, b),
i.e. the remainder.

3. Re-arrange the third last equation for the remainder and substitute into the equation
formed from step 2.

4. Collect together terms in involving a and b.

5. Repeat steps 2-4 until only terms involving a and b exist.

Note that this is not the only way to express the gcd as a linear combination but it will always give a
solution. The set of all solutions can, however, be found from this solution. A simpler example will
be easier to follow.

Example
Problem:
Find all solutions of the equation gcd(48, 20) = 48x + 20y.
Solution:
Using the Euclidean algorithm gives:
48 = 2.20 + 8
20 = 2.8 + 4
8 = 2.4 + 0

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 25

Working backwards to find one linear combination gives:


4 = 20 − 2.8 (re-arranged second-last line)
4 = 20 − 2(48 − 2.20) (substitute re-arranged first line into above)
4 = 5.20 − 2.48
Thus, one solution is 4 = 48x + 20y where x = − 2 and y = 5
so 48x + 20y = − 2.48 + 5.20
Rearranging this gives: 48(x + 2) = 20(5 − y)
Divide through by the gcd of 4 to give: 12(x + 2) = 5(5 − y)
Since 12 and 5 have no common factors, x + 2 must be a multiple of 5 and 5 − y must be
a multiple of 12, thus:
x + 2 = 5m so x = 5m − 2
5 − y = 12m so y = 5 − 12m
The general solution is therefore: 4 = 48(5m − 2) + 20(5 − 12m)

There is a shortcut to the general solution.

Key point

Suppose that ax + by = d where d = gcd(a, b)


If, by the Euclidean algorithm, the particular solutions for x and y are x 0 and y0 , then the
general solutions xn and yn are found as follows:

xn = x0 + db m
and
a
yn = y0 − d m
Note that the xn solution has a '+' and the y n solution has a '-'.

In the last example, the linear combination took the form:


gcd (a, b) =ax + by
4 =48x + 20y
where a = 48, b = 20 and d = gcd(48, 20) = 4.
The particular solution took the form: 4 = 48. − 2 + 20.5, where x 0 = − 2 and y0 = 5.
Given that we now know x 0 = − 2, y0 = 5, a = 48, b = 20 and d = 4 we can now work out the
general solution using the short cut.
4 =48xn + 20yn
   a 
b
4 =48 x0 + m + 20 y0 − m
d d
   
20 48
4 =48 −2 + m + 20 5 − m
4 4
4 =48 (−2 + 5m) + 20 (5 − 12m)

© H ERIOT-WATT U NIVERSITY
26 TOPIC 11. EUCLID'S ALGORITHM

Re-writing the terms in the same order as the previous example gives:
4 = 48(5m − 2) + 20(5 − 12m)
A linear combination of two integers equal to the gcd is a special example of the simplest type of
Diophantine equation.

Key point

A Diophantine equation is an equation with integer coefficients in two or more unknowns


which is to be solved in the integers.

In its simplest form in two unknowns, the linear Diophantine equation is ax + by = c

If gcd(a, b) = d is found, then such an equation has a solution if, and only if, d|c.

The full method of then solving the equation is very similar to that for finding the general solution of
the equation ax + by = c but with one extra step. Suppose that c = dn, then after finding the
particular solution ax + by = d, the whole equation is multiplied up to give
nax + nby = dn = c and the general solution is found in the same way as before.

Example
Problem:
Find the solution to the linear Diophantine equation 18 = 90x + 12y if it exists.
Solution:
First we need to find the gcd(90, 12). Use the Euclidean Algorithm to do this.
90 = 7.12 + 6
12 = 2.6 + 0
gcd (90, 12) = 6
Since 6|18, there is a solution to the Diophantine equation.
Taking the first line of the Euclidean algorithm and rearranging for the remainder
[gcd(90, 12) = 6] we get: 6 = 90.1 + 12.(−7)
Comparing this to the original equation 18 = 90x + 12y we need to check that 6|18, which
it does. A solution therefore exists.
To make the LHS of 6 = 90.1 + 12.(−7) equal to the LHS of 18 = 90x + 12y we must
multiply by 3.
18 = 90.3 + 12.(−21)
Note that when we multiply by 3, we retain 90 and 12 because these appear in the original
equation 18 = 90x + 12y. By comparing the particular solution to gcd(a, b) = ax 0 + by0
we now have a particular solution where x 0 = 3, y0 = − 21, a = 90, b = 12 and
d = gcd(90, 12) = 6.
We have all the information we need to use the short cut to get the general solution.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 27

18 =90xn + 12yn
   a 
b
18 =90 x0 + m + 12 y0 − m
d d
   
12 90
18 =90 3 + m + 12 −21 − m
6 6
18 =90 (3 + 2m) + 20 (−21 − 15m)

Note: Fermat's conjecture, or as more commonly known, Fermat's last theorem, states that there is
no solution to the Diophantine equation x n + y n = z n in the integers for n > 2. This was one of
the most famous 'unproved' results until Andrew Wiles presented a proof in the mid 1990s.

The GCD as a linear combination practice Go online

Q41: Use the Euclidean algorithm to find integers x and y such that 247x + 139y = 1.
...............................................

Q42: Use the Euclidean algorithm to find integers x and y such that 252x + 160y = 4
...............................................

Q43: Use the Euclidean algorithm to find integers x and y such that gcd(297, 180) = 297x +
180y
...............................................

Q44: Solve the linear Diophantine equation 30 = 85x + 105y


...............................................

Q45: Solve the linear Diophantine equation 28 = 91x + 161y

The GCD as a linear combination exercise Go online

This is a worthwhile exercise on finding both linear combinations of the gcd of two integers
and of solving a linear Diophantine equation.

Q46: Use the Euclidean algorithm to find integers x and y such that:
gcd(693, 84) = 693x + 84y
...............................................
Q47: Use the Euclidean algorithm to find integers x and y such that:
gcd(10080, 3705) = 10080x + 3705y
...............................................
Q48: Use the Euclidean algorithm to find a solution to the equation:
gcd(336, 180) = 336x + 180y
...............................................

© H ERIOT-WATT U NIVERSITY
28 TOPIC 11. EUCLID'S ALGORITHM

Q49: Use the Euclidean algorithm to solve for x and y when:


14 = 1078x + 420y
...............................................

Q50: Find the general solution of the equation gcd(585, 104) = 585x + 104y using the
Euclidean algorithm.
...............................................

Q51: Solve the linear Diophantine equation 20 = 204x + 56y

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 29

11.4 Learning points


Euclid's algorithm
The division algorithm

• If a and b are integers, b = 0, then there are unique integers q and r such that a = qb + r
where 0  r  |b|
(As in any division, q is the quotient and r is the remainder.)
• If a and b are given, then there are two cases to consider.
1. If a > 0, then to find:
◦ the quotient q, calculate a : the whole number is the quotient.
b
◦ the remainder r, calculate what is left over after a
b
2. If a < 0, then to find:
◦ the quotient q, calculate a : the quotient is one less than the integer value.
b
◦ the remainder r, calculate what needs to be added on to find a after the quotient q is
multiplied by b.

Number bases

• To convert a number of a base other than 10 into a base 10 number, multiply the digit by its
'place' value, e.g. convert 4025 to base 10:

52 51 50
↓ ↓ ↓
4 0 2
4.52 + 0.51 + 2.50
= 4.25 + 0.5 + 2.1
= 100 + 0 + 2
= 10210
• To convert a base 10 number into another base we repeatedly divide by the given base using
the division algorithm to record the remainders. The remainders are then read in reverse order
to give the number, e.g. convert 345 10 to base 8 using the division algorithm:
345 = 43.8 + 1
43 = 5.8 + 3
5 = 0.8 + 5
Reading the remainders off in reverse order, the answer is 531 8

The Euclidean algorithm

• The Euclidean algorithm is a process that works out the greatest common divisor, gcd(a, b),
between two numbers a and b. It is also known as the highest common factor (hcf).
• To work out gcd(a, b), we write a and b as a linear combination in the form:
a = qb + r (0 ≤ b < |r|)
where a is the larger of the two numbers, b is the other number, q is a multiplier of b and r is
the remainder.

© H ERIOT-WATT U NIVERSITY
30 TOPIC 11. EUCLID'S ALGORITHM

• The Euclidean algorithm is processed as follows, e.g. find gcd(252, 140):


252 = 1.140 + 112
140 = 1.112 + 28
112 = 4.28 + 0
Stop when the remainder is 0, giving gcd(252, 140) = 28

The GCD as a linear combination

• Two numbers can be written as a linear combination of their gcd, i.e.


gcd(a, b) = ax + by
The Euclidean algorithm allows us to work out x and y, given a and b.
• The method for finding x and y given gcd(a, b) = ax + by is as follows, e.g. gcd(16, 6) =
16x + 6y:
Use the Euclidean algorithm to work out gcd(16, 6)
16 = 2.6 + 4
6 = 1.4 + 2
4 = 2.2 + 0
Therefore, gcd(6, 16) = 2
Now, we work in reverse:

1. Take the second last equation 6 = 1.4 + 2 and rearrange for gcd(6, 16) = 2:
2 = 6 − 1.4
2. Take the third last equation 16 = 2.6 + 4 and rearrange for the remainder of 4:
4 = 16 − 2.6
Take this rearrangement and substitute for 4 into the expression in step 1, then collect
terms for 6 and 16:
2 = 6 − 1 (16 − 2.6)
2 = 6 − 1.16 + 2.6
2 = − 1.16 + 3.6
3. Compare the answer with the target of gcd(16, 6) = 16x + 6y:
gcd(16, 6) = 2 so x = − 1 and y = 3

Note that steps 2-4 should be repeated as many times as necessary until an expression
involving only the gcd and multiples of a and b remain.

Diophantine equations

• A Diophantine equation is an equation with integer coefficients and integer solutions.


Given a Diophantine equation of the form ax + by = d where d = gcd(a, b), the Euclidean
algorithm solves to give particular solutions for x and y of x 0 and y0 . The general solutions x n
and yn are found as follows:

◦ xn = x0 + b m
d
◦ y = y0 − a m
d

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 31

e.g. Find the solution to the linear Diophantine equation 2 = 16x + 6y if it exists.
We solved this above to get gcd(6, 16) = 2, x = − 1 and y = 3
For the general solution, we know that x 0 = − 1, y0 = 3, a = 16, b = 6 and d =
gcd(16, 6) = 2, so the general solution becomes:
2 = 16xn + 6yn
   a 
b
2 = 16 x0 + m + 6 y0 − m
d d
   
6 16
2 = 16 −1 + m +6 3− m
2 2
2 = 16 (−1 + 3m) + 6 (3 − 8m)

© H ERIOT-WATT U NIVERSITY
32 TOPIC 11. EUCLID'S ALGORITHM

11.5 Proofs
Proof 1: The division algorithm
Let S be the set {a − xb such that x ∈ Z and a − xb ≥ 0}

The steps in the proof are as follows.

1. Show that the set S is nonempty.

2. Show that S contains a least element.

3. Show that r < b.

4. Show the uniqueness of q and r.


1.
To show that S is a nonempty set, we must show that it contains the elements a − xb such that
x ∈ Z and a − xb ≥ 0. We do this in the following way:
By the condition on b in the definition of the division algorithm b ≥ 1.
Multiplying both sides by |a|, to ensure that the answer is positive, we get:
|a| b  |a|
Now add a to both sides:
a + |a| b  a + |a|
a − (− |a|) b  a + |a|
By letting x = − |a| we then have:
a − xb  a + |a|
Since a ∈ Z, then it can be positive or negative. The minimum value of a + |a| is therefore 0
and so we can write:
a − xb ≥ 0
Therefore, if x = −|a|, then a − xb ∈ S.
2.
Show that S contains a least element:
by the well ordering principle, since S is nonempty, it contains a least element, say r, such that
r = a − qb for some integer q and r ≥ 0
3.
To prove that r < b we use proof by contradiction. We will see this type of proof in the topic
Methods of Proof. We start by setting up a false assumption then work through logical steps to
show that a contradiction happens. This is done as follows:
Assume that r ≥ b
From the division algorithm r = a − qb we can also say that r = a − (q + 1)b so the RHS
becomes:
a − qb − b
From the division algorithm we know that r = a − qb, so substituting in the previous expression
we get:
r − b
We can say that r − b ≥ 0 based on our assumption that r ≥ b, but r − b < r which contradicts
the fact that r is chosen as the least element in S (from step 2) so the assumption that r ≥ b is
false and the original conjecture r < b is true.

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 33

4.
For this proof, we start by assuming that there are two possible values for q and r. By following
logical steps we will then show that the two values of q are equal and the two values of r are
equal.
Suppose that a = bq 1 + r1 and a = bq2 + r2 with the conditions 0 ≤ r1 < b and 0 ≤ r2 < b.
Since both expressions are equal to a we can write:
bq1 + r1 = bq2 + r2
Collecting like terms and factorising we get:
bq1 − bq2 = r2 − r1
b (q1 − q2 ) = r2 − r1
The RHS is therefore a multiple of b, but the conditions on r 1 and r2 state that they must be less
than b and greater than or equal to zero.
The maximum value that r 1 and r2 can take individually is b and their minimum values can be
zero.
Therefore the maximum value of r 2 − r1 occurs when r2 is as large as possible, i.e. r2 < b and
r1 is as small as possible, i.e r1 = 0. This gives r2 − r1 < b.
The minimum value of r 2 − r1 occurs when r2 is as small as possible, i.e. r2 = 0 and r1 is as
large as possible, i.e. r1 < b. This gives −b < r2 − r1 .
Putting these both together gives −b < r 2 − r1 < b
The only multiple of b between −b and b is zero.
Hence,
r2 − r1 = 0 ⇒ r2 = r1
and
b(q1 − q2 ) = 0 ⇒ q1 = q2 (since b = 0)

Proof 2: Successive Fibonacci numbers are relatively prime


To prove this we will use proof by contradiction.
Assume that consecutive Fibonacci numbers u n − 1 and un are relatively prime but that un and
un + 1 have some common factor d > 1.
By the definition of Fibonacci numbers, u n + 1 = un + un − 1 .
Rearranging gives un − 1 = un + 1 − un .
Since d divides both un andun + 1 , then it also divides un − 1 . (This is a divisibility rule).
This means that un and un − 1 have a common factor of d > 1, so they cannot be relatively prime.
This contradicts our assumption.
Our assumption that un and un + 1 have some common factor d > 1 is therefore false.
Hence, un and un + 1 must have gcd(un , un + 1 ) = 1 for all n ≥ 1 and are therefore relatively
prime.

© H ERIOT-WATT U NIVERSITY
34 TOPIC 11. EUCLID'S ALGORITHM

Proof 3: The Euclidean algorithm


We will prove this using strong mathematical induction, not weak mathematical induction as you
will learn in the topic Methods of Proof.
Let Fm represent a Fibonacci number for m ≥ 1, m ∈ Z and n ∈ Z + .

1. The statement is clearly true for the integers n = 1, 2 and 3 since,


• The first Fibonacci number is F1 = 1
• The third Fibonacci number is F 3 = 2
• The fourth Fibonacci number is F 4 = 3

i.e. the first three positive integers are the sum of single Fibonacci numbers.

2. Suppose that the conjecture is true for all n ≤ k (this is the induction hypothesis for strong
induction, while n = k is used for weak induction).
i.e. we have assumed that any integer ≤ k can be written as the sum of Fibonacci
numbers.
We will prove that the statement is true for n = k + 1.
If k + 1 = Fm for some m, then it is trivially correct.
i.e. if the integer k + 1 is already a Fibonacci number, it is automatically the sum of a
single Fibonacci number. This was exemplified in step 1.
In other cases we find the m such that Fm < k + 1 < Fm + 1 .
Now subtract Fm from each part of the inequality:
0 <k + 1 − Fm < Fm+1 − Fm
0 <k + 1 − Fm < Fm−1
Let q = k + 1 − Fm , then we can write q as the sum of nonconsecutive Fibonacci
numbers because k + 1 − Fm < k + 1 which means that q < k + 1.
i.e. q is an integer less than k + 1 which means that q ≤ k and we stated as an
assumption, at the beginning of step 2, that the conjecture was true for all integers n ≤ k.
We also note that this sum does not contain F m − 1 because from the inequality above
q = k + 1 − Fm < Fm − 1 .
So if we add Fm to the sum of nonconsecutive Fibonacci numbers for q we have a
nonconsecutive sum of Fibonacci numbers for k + 1 as well, i.e. k + 1 = q + F m ,
and the statement is true for n = k + 1.

Therefore, by strong mathematical induction, we have proven that every positive integer n can
be written as the sum of one or more distinct Fibonacci numbers.

11.6 Extended information


This is a site for information about prime numbers which is easy to read and understand: http://ww
w.utm.edu/research/primes/largest.html
This site gives a good explanation of the Euclidean algorithm:
http://www.cut-the-knot.com/blue/Euclid.shtml

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 35

There are some interesting paradoxes in this site relating to logic number theory and maths in
general: http://forum.swarthmore.edu/~isaac/problems/paradox.html
Euclid
The Euclidean algorithm is given in Euclid's seventh book of the 'Elements', but there is evidence to
suggest that it was known before this time.
Lame
The French mathematician Gabriel Lame produced a theorem which states that the number of steps
required in the Euclidean algorithm is never greater than five times the number of digits in the lesser
of the two numbers.
Godel
A 20th century mathematician famous for his incompleteness theorem. Look this one up yourself
online.

© H ERIOT-WATT U NIVERSITY
36 TOPIC 11. EUCLID'S ALGORITHM

11.7 End of topic test


End of topic 11 test Go online

The division algorithm

Q52: Find two integers q and r such that a = qb + r when a = 382 and b = 47.
...............................................

Q53: Find two integers q and r such that a = qb + r when a = − 241 and b = 16.

Number bases

Q54: Use the division algorithm to express 85 10 in base 2.


...............................................

Q55: Use the division algorithm to express 185 10 in base 8.


...............................................

Q56: Use the division algorithm to express 2354 10 in base 16.


...............................................

Q57: Write the number 10111 2 in base 10.


...............................................

Q58: Write the number 3201 4 in base 10.


...............................................

Q59: Write the number 6410 7 in base 10.


...............................................

Q60: Write the number 7562 8 in base 10.


...............................................

Q61: Write the number E5B1 16 in base 10.

The Euclidean algorithm

Q62: Find the greatest common divisor of 1289 and 233.


...............................................

Q63: Work out the highest common factor of 36 and 584.


...............................................

Q64: Work out gcd(235, 562).


...............................................

© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 37

27
Q65: Simplify the fraction 294 .
...............................................
3276
Q66: Use the Euclidean algorithm to simplify the fraction 4056 .

The GCD as a linear combination

Q67: Find x and y such that 125x + 35y = gcd(125, 35)


...............................................

Q68: Solve the linear Diophantine equation 12 = 39x + 51y


...............................................

Q69: Solve the linear Diophantine equation 20 = 26x + 38y

© H ERIOT-WATT U NIVERSITY
38 GLOSSARY

Glossary
diophantine equation
an equation with integer coefficients in one or more unknowns which is to be solved in the
integers

division algorithm
if a and b are integers, b = 0, then there are unique integers q and r such that a = qb + r
where 0 ≤ r < |b|

Euclidean algorithm
the repeated application of the division algorithm to find the greatest common divisor of two
numbers

fundamental theorem of arithmetic


states that every positive integer > 1 is a prime or can be expressed as a unique product of its
prime factors

greatest common divisor


the greatest common divisor (GCD) of two integers a and b, where at least one is non-zero,
denoted gcd(a, b), is the positive integer d such that d|a and d|b, and if c|a and c|b, then c ≤ d

prime number
a positive integer greater than 1 which has no positive divisors except itself and 1

relatively prime
the integers a and b, where at least one is non-zero, are relatively prime when gcd(a, b) = 1

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 39

Answers to questions and activities


Topic 11: Euclid's algorithm
The division algorithm practice (page 9)

Q1:
All of the possible forms of a number divided by 8 are:
8k, 8k + 1, 8k + 2, 8k + 3, 8k + 4, 8k + 5, 8k + 6 and 8k + 7
Of these, the even forms are 8k, 8k + 2, 8k + 4, 8k + 6 as each of these is of the form 2m for
some integer m.

Q2:
2584
Start with ab : 158 = 16 r = 56
We have 2584 = 16.158 + 56
So q = 16 and r = 56.

Q3:
−148
Start with ab : 13 = −11 r = −5
We have −148 = − 11.13 + (−5)
So q = − 11 and r = − 5
But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 12
−12.13 = − 156 so to make it up to -148 we need to add on 8.
We have −148 = − 12.13 + 8
So q = − 12 and r = 8.
Check this with you calculator.

Q4:
−452
Start with ab : 11 = −41 r = −1
We have −452 = − 41.11 + (−1)
So q = − 41 and r = − 1.
But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 42
−42.11 = − 462 so to make it up to -452 we need to add on 10.
We have −452 = − 42.11 + 10
So q = − 42 and r = 10.

Q5:
−168
Start with ab : 23 = −7 r = −7
We have −168 = − 7.23 + (−7)
So q = − 7 and r = − 7

© H ERIOT-WATT U NIVERSITY
40 ANSWERS: UNIT 1 TOPIC 11

But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 8
−8.23 = − 184 so to make it up to -168 we need to add on 16.
We have −168 = − 8.23 + 16
So q = − 8 and r = 16.

Q6:
235
Start with ab : −19 = −12 r=7
We have 235 = − 12. − 19 + 7
So q = − 12 and r = 7.

The division algorithm exercise (page 10)

Q7:
−42
Start with ab : 5 = −8 r = −2
We have −42 = − 8.5 + (−2)
So q = − 8 and r = − 2.
But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 9
−9.5 = − 45 so to make it up to -42 we need to add on 3
We have −42 = − 9.5 + 3
So q = − 9 and r = 3.

Q8:
25
Start with ab : −7 = −3 r = 4
We have 25 = − 3. − 7 + 4
So q = − 3 and r = 4.

Q9:
14
Start with ab : −9 = −1 r = 5
We have 14 = − 1. − 9 + 5
So q = − 1 and r = 5.

Q10:
−1
Start with ab : 3 = 0 r = −1
We have −1 = 0.3 + (−1)
So q = 0 and r = − 1.
But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case, q = − 1

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 41

−1.3 = − 3 so to make it up to -1 we need to add on 2.


We have −1 = − 1.3 + 2
So q = − 1 and r = 2.

Q11:
4
Start with ab : 9 =0 r=4
We have 4 = 0.9 + 4
So q = 0 and r = 4.

Q12:
−12
Start with ab : 3 = −4 r = 0
We have −12 = − 4.3 + 0
So q = − 4 and r = 0.

Number bases practice (page 13)

Q13:
To convert the binary number to base 10, multiply each digit by its column heading and add all of
these together.
1.24 + 1.23 + 1.22 + 0.21 + 1.20
= 1.16 + 1.8 + 1.4 + 0.2 + 1.1
= 16 + 8 + 4 + 0 + 1
= 2910

Q14:
To convert the octal number to base 10, multiply each digit by its column heading and add all of
these together.
7.84 + 3.83 + 2.82 + 0.81 + 1.80
= 7.4096 + 3.512 + 2.64 + 0.8 + 1.1
= 28672 + 1536 + 128 + 0 + 1
= 3033710

Q15:
Hexadecimal numbers use the first 10 numbers 0-9 then continue with A, B, C, D, E, F where A
= 11, B = 12, C = 13, D = 14, E = 15, F = 16.
To convert the hexadecimal number to base 10, multiply each digit (converted from a letter, if
necessary) by its column heading and add all of these together.
F.164 + 1.163 + E.162 + A.161 + 3.160
= 15.65536 + 1.4096 + 14.256 + 10.16 + 3.1
= 983040 + 4096 + 3584 + 160 + 3
= 99088310

© H ERIOT-WATT U NIVERSITY
42 ANSWERS: UNIT 1 TOPIC 11

Q16:
Divide the given number by the base number 2 and record the remainders.
25384 = 12692.2 + 0
12692 = 6346.2 + 0
6346 = 3173.2 + 0
3173 = 1586.2 + 1
1586 = 793.2 + 0
793 = 396.2 + 1
396 = 198.2 + 0
198 = 99.2 + 0
99 = 49.2 + 1
49 = 24.2 + 1
24 = 12.2 + 0
12 = 6.2 + 0
6 = 3.2 + 0
3 = 1.2 + 1
1 = 0.2 + 1
Read the remainder upwards from the last line of working to get the binary form for 25384 as
110001100101000 2.

Q17:
Divide the given number by the base number 8 and record the remainders.
25384 = 3173.8 + 0
3173 = 396.8 + 5
396 = 49.8 + 4
49 = 6.8 + 1
6 = 0.8 + 6
Read the remainder upwards from the last line of working to get the octal form for 25384 as 61450 8.

Q18:
Divide the given number by the base number 16 and record the remainders.
(Remember that a remainder 11 = A, 12 = B, 13 = C, 14 = D, 15 = E, 16 = F.)
25384 = 1586.16 + 8
1586 = 99.16 + 2
99 = 6.16 + 3
6 = 0.16 + 6
Read the remainder upwards from the last line of working to get the hexadecimal form for 25384 as
632816.

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 43

Number bases exercise (page 14)

Q19:
332 = 166.2 + 0
166 = 83.2 + 0
83 = 41.2 + 1
41 = 20.2 + 1
20 = 10.2 + 0
10 = 5.2 + 0
5 = 2.2 + 1
2 = 1.2 + 0
1 = 0.2 + 1
Read the remainder upwards from the last line of working to get the binary form for 332 as
101001100 2.
Q20:
501 = 250.2 + 1
250 = 125.2 + 0
125 = 62.2 + 1
62 = 31.2 + 0
31 = 15.2 + 1
15 = 7.2 + 1
7 = 3.2 + 1
3 = 1.2 + 1
1 = 0.2 + 1
Read the remainder upwards from the last line of working to get the binary form for 501 as
111110101 2.
Q21:
43 = 21.2 + 1
21 = 10.2 + 1
10 = 5.2 + 0
5 = 2.2 + 1
2 = 1.2 + 0
1 = 0.2 + 1
Read the remainder upwards from the last line of working to get the binary form for 43 as 101011 2.
Q22:
63 = 31.2 + 1
31 = 15.2 + 1
15 = 7.2 + 1
7 = 3.2 + 1
3 = 1.2 + 1
1 = 0.2 + 1

© H ERIOT-WATT U NIVERSITY
44 ANSWERS: UNIT 1 TOPIC 11

Read the remainder upwards from the last line of working to get the binary form for 63 as 111111 2.

Q23:
347 = 43.8 + 3
43 = 5.8 + 3
5 = 0.8 + 5
Read the remainder upwards from the last line of working to get the octal form for 647 as 533 8 .

Q24:
2924 = 365.8 + 4
365 = 45.8 + 5
45 = 5.8 + 5
5 = 0.8 + 5
Read the remainder upwards from the last line of working to get the octal form for 2924 as 5554 8.

Q25:
3012 = 376.8 + 4
376 = 47.8 + 0
47 = 5.8 + 7
5 = 0.8 + 5
Read the remainder upwards from the last line of working to get the octal form for 3012 as 5704 8.

Q26:
534 = 66.8 + 6
66 = 8.8 + 2
8 = 1.8 + 0
1 = 0.8 + 1
Read the remainder upwards from the last line of working to get the octal form for 534 as 1026 8.

Q27:
4014 = 250.16 + 14 (note: 14 ≡ E)
250 = 15.16 + 10 (note: 10 ≡ A)
15 = 0.16 + 15 (note: 15 ≡ F)
Read the remainder upwards from the last line of working to get the hexadecimal form for 4014 as
FAE16.

Q28:
364 = 22.16 + 12 (note: 12 ≡ C)
22 = 1.16 + 6
1 = 0.16 + 1
Read the remainder upwards from the last line of working to get the hexadecimal form for 364 as
16C16.

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 45

Q29:
2179 = 136.16 + 3
136 = 8.16 + 8
8 = 0.16 + 8
Read the remainder upwards from the last line of working to get the hexadecimal form for 2179 as
88316 .

Q30:
5034 = 314.16 + 10 (note: 10 ≡ A)
314 = 19.16 + 10 (note: 10 ≡ A)
19 = 1.16 + 3
1 = 0.16 + 1
Read the remainder upwards from the last line of working to get the hexadecimal form for 5034 as
13AA16.

The Euclidean algorithm practice (page 22)

Q31:
1365 = 4.299 + 169
299 = 1.169 + 130
169 = 1.130 + 39
130 = 3.39 + 13
39 = 3.13 + 0
gcd (299, 1365) = 13

Q32:
The highest common factor is the same as the gcd.
5187 = 6.760 + 627
760 = 1.627 + 133
627 = 4.133 + 95
133 = 1.95 + 38
95 = 2.38 + 19
38 = 2.19 + 0
Since gcd(760, 5187) = 19, then hcf(760, 5187) = 19

© H ERIOT-WATT U NIVERSITY
46 ANSWERS: UNIT 1 TOPIC 11

Q33:
For co-prime integers, the gcd is 1.
10465 = 1.5643 + 4822
5643 = 1.4822 + 821
4822 = 5.821 + 717
821 = 1.717 + 104
717 = 6.104 + 93
104 = 1.93 + 11
93 = 8.11 + 5
11 = 2.5 + 1
5 = 5.1 + 0
This gcd is 1 and the numbers have no common factor other than 1, therefore they are relatively
prime.

Q34:
5184 = 1.3024 + 2160
3024 = 1.2160 + 864
2160 = 2.864 + 432
864 = 2.432 + 0
gcd (3024, 5184) = 432

Q35:
To simplify the fraction, we need to work out gcd(372, 4340)
4340 = 11.372 + 248
372 = 1.248 + 124
248 = 2.124 + 0
Since gcd(372, 4340) = 124 we can simplify the fraction by dividing the numerator and denominator
by 124.
372 3
Therefore, 4340 = 35

Q36:
To simplify the fraction we need to work out gcd(19327, 25602)
25602 = 1.19327 + 6275
19327 = 3.6275 + 502
6275 = 12.502 + 251
502 = 2.251 + 0
Since gcd(19327, 25602) = 251 we can simplify the fraction by dividing the numerator and
denominator by 251.
19327 77
Therefore, 25602 = 102

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 47

The Euclidean algorithm exercise (page 23)

Q37:
Using the Euclidean algorithm to find gcd(943, 779)
943 = 1.779 + 164
779 = 4.164 + 123
164 = 1.123 + 41
123 = 3.41 + 0
Therefore, gcd(943, 779) = 41.

Q38:
First we must use the Euclidean algorithm to find gcd(5141, 3763)
5141 = 1.3763 + 1378
3763 = 2.1378 + 1007
1378 = 1.1007 + 371
1007 = 2.371 + 265
371 = 1.265 + 106
265 = 2.106 + 53
106 = 2.53 + 0
Therefore, gcd(5141, 3763) = 53
71
Dividing the numerator and denominator by 53 gives the simplified fraction 97

Q39:
First we must use the Euclidean algorithm to find gcd(1349, 3763)
3053 = 2.1349 + 355
1349 = 3.355 + 284
355 = 1.284 + 71
284 = 4.71 + 0
Therefore, gcd(1349, 3763) = 71
19
Dividing the numerator and denominator by 71 gives the simplified fraction 43

Q40:
First we must use the Euclidean algorithm to find gcd(3276, 4056)
4056 = 1.3276 + 780
3276 = 4.780 + 156
780 = 5.156 + 0
Therefore, gcd(3276, 4056) = 156
21
Dividing the numerator and denominator by 156 gives the simplified fraction 26

© H ERIOT-WATT U NIVERSITY
48 ANSWERS: UNIT 1 TOPIC 11

The GCD as a linear combination practice (page 27)

Q41:
Use the Euclidean algorithm to find gcd(247, 139).
247 = 1.139 + 108
139 = 1.108 + 31
108 = 3.31 + 15
31 = 2.15 + 1
15 = 15.1 + 0
So gcd(247, 139) = 1
Now, working backwards from 31 = 2.15 + 1:
1 = 31 − 2.15
1 = 31 − 2 (108 − 3.31) → 1 = −2.108 + 7.31
1 = − 2.108 + 7 (139 − 1.108) → 1 = 7.139 − 9.108
1 = 7.139 − 9 (247 − 1.139) → 1 = −9.247 + 16.139
So 247x + 139y = 1 where x = − 9 and y = 16

Q42:
Use the Euclidean algorithm to find gcd(252, 160)
252 = 1.160 + 92
160 = 1.92 + 68
92 = 1.68 + 24
68 = 2.24 + 20
24 = 1.20 + 4
20 = 5.4 + 0
So gcd(252, 160) = 4
Now, working backwards from 24 = 1.20 + 4:
4 = 24 − 1.20
4 = 24 − 1 (68 − 2.24) → 4 = −1.68 + 3.24
4 = − 1.68 + 3 (92 − 1.68) → 4 = 3.92 − 4.68
4 = 3.92 − 4 (160 − 1.92) → 4 = −4.160 + 7.92
4 = − 4.160 + 7 (252 − 1.160) → 4 = 7.252 − 11.160
So 252x + 160y = 4 where x = 7 and y = − 11

Q43:
Use the Euclidean algorithm to find gcd(297, 180)
297 = 1.180 + 117
180 = 1.117 + 63
117 = 1.63 + 54
63 = 1.54 + 9
54 = 6.9 + 0
So gcd(297, 180) = 9

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 49

Now, working backwards from 63 = 1.54 + 9:


9 = 63 − 1.54
9 = 63 − 1 (117 − 1.63) → 9 = −1.117 + 2.63
9 = − 1.117 + 2 (180 − 1.117) → 9 = 2.180 − 3.117
9 = 2.180 − 3 (297 − 1.180) → 9 = −3.297 + 5.180
So 9 = 297x + 180y where x = − 3 and y = 5

Q44:
First we need to find gcd(85, 105)
105 = 1.85 + 20
85 = 4.20 + 5
20 = 4.5 + 0
So, gcd(85, 105) = 5 and 5|30 so there is a solution.
Now, working backwards from 85 = 4.20 + 5
5 = 85 − 4.20
5 = 85 − 4 (105 − 1.85)
5 = 5.85 − 4.105
Multiply by 6 since 6 × 5 = 30: 30 = 30.85 − 24.105
The general solution is given by:

x = 30 + 105
5 m = 30 + 21m and y = −24 − 85
5 m = −24 − 17m
The general solution is 30 = 85(30 + 21m) + 105(−24 − 17m)

Q45:
First we need to find gcd(91, 161)
161 = 1.91 + 70
91 = 1.70 + 21
70 = 3.21 + 7
21 = 3.7 + 0
So, gcd(91, 161) = 7 and 7|28 so there is a solution.
Now, working backwards from 70 = 3.21 + 7
7 = 70 − 3.21
7 = 70 − 3 (91 − 1.70) → 7 = 4.70 − 3.91
7 = 4 (161 − 1.91) − 3.91 → 7 = −7.91 + 4.161
Multiply by 4 since 4 × 7 = 28: 28 = − 28.91 + 16.161
The general solution is given by:
91
x = −28 + 1617 m = −28 + 23m and y = 16 − 7 m = 16 − 13m
The general solution is 28 = 91(−28 + 23m) + 161(16 − 13m)

© H ERIOT-WATT U NIVERSITY
50 ANSWERS: UNIT 1 TOPIC 11

The GCD as a linear combination exercise (page 27)

Q46:
First we need to work out gcd(693, 84)
693 = 8.84 + 21
84 = 4.21 + 0
So gcd(693, 84) = 21
Now we work backwards from 693 = 8.84 + 21
21 = 1.693 − 8.84
Upon comparison with our target we have:
gcd(693, 84) = 21, x = 1 and y = − 8

Q47:
Find gcd(10080, 3705)
10080 = 2.3705 + 2670
3705 = 1.2670 + 1035 (line a)
2670 = 2.1035 + 600 (line b)
1035 = 1.600 + 435 (line c)
600 = 1.435 + 165 (line d)
435 = 2.165 + 105 (line e)
165 = 1.105 + 60 (line f)
105 = 1.60 + 45 (line g)
60 = 1.45 + 15 (line h)
45 = 3.15 + 0 (line i)
So gcd(10080, 3705) = 15
Working backwards gives:
15 = 60 − 1.45 (using line h)
15 = 60 − 1 (105 − 1.60) = −1.105 + 2.60 (using line g)
15 = − 1.105 + 2 (165 − 1.105) = 2.165 − 3.105 (using line f)
15 = 2.165 − 3 (435 − 2.165) = −3.435 + 8.165 (using line e)
15 = − 3.435 + 8 (600 − 1.435) = 8.600 − 11.435 (using line d)
15 = 8.600 − 11 (1035 − 1.600) = −11.1035 + 19.600 (using line c)
15 = − 11.1035 + 19 (2670 − 2.1035) = 19.2670 − 49.1035 (using line b)
15 = 19.2670 − 49 (3705 − 1.2670) = −49.3705 + 68.2670 (using line a)
15 = − 49.3705 + 68 (10080 − 2.3670) = 68.10080 − 185.3705
Upon comparison with our target we have:
gcd(10080, 3705) = 15, x = 68 and y = − 185

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 51

Q48:
Find gcd(336, 180)
336 = 1.180 + 156
180 = 1.156 + 24
156 = 6.24 + 12
24 = 2.12 + 0
gcd(336, 180) = 12
Working backwards gives:
12 = 156 − 6.24
12 = 156 − 6 (180 − 1.156) = −6.180 + 7.156
12 = − 6.180 + 7 (336 − 1.180) = 7.336 − 13.180
12 = 336.7 − 180.13
Upon comparison with our target we have:
gcd(336, 1180) = 12, x = 7 and y = − 13

Q49:
Find gcd(1078, 420)
1078 = 2.420 + 238
420 = 1.238 + 182
238 = 1.182 + 56
182 = 3.56 + 14
56 = 4.14 + 0
gcd(1078, 420) = 14
Working backwards gives:
14 = 182 − 3.56
14 = 182 − 3 (238 − 1.182) = −3.238 + 4.182
14 = − 3.238 + 4 (420 − 1.238) = 4.420 − 7.238
14 = 4.420 − 7 (1078 − 2.420) = −7.1078 + 18.420
14 = 1078. − 7 + 420.18
Upon comparison with our target we have:
gcd(1078, 420) = 14, x = − 7 and y = 18

Q50:
Find gcd(585, 104)
585 = 5.104 + 65
104 = 1.65 + 39
65 = 1.39 + 26
39 = 1.26 + 13
26 = 2.13 + 0
gcd(585, 104) = 13
Working backwards gives:

© H ERIOT-WATT U NIVERSITY
52 ANSWERS: UNIT 1 TOPIC 11

13 = 39 − 1.26
13 = 39 − 1 (65 − 1.39) = −1.65 + 2.39
13 = − 1.65 + 2 (104 − 1.65) = 2.104 − 3.65
13 = 2.104 − 3 (585 − 5.104) = −3.585 + 17.104
13 = 585. − 3 + 104.17
Upon comparison with our target we have:
gcd(585, 104) = 13, x = − 3 and y = 17
For the general solution:
585
x = −3 + 104
13 m = −3 + 8m and y = 17 − 13 m = 17 − 45m
Thus, the general solution is 13 = 585(−3 + 8m) + 104(17 − 45m)

Q51:
Find gcd(204, 56)
204 = 3.56 + 36
56 = 1.36 + 20
36 = 1.20 + 16
20 = 1.16 + 4
16 = 4.4 + 0
gcd(204, 56) = 4 and 4|20 so there is a solution.
Working backwards gives:
4 = 20 − 1.16
4 = 20 − 1 (36 − 1.20) = −1.36 + 2.20
4 = − 1.36 + 2 (56 − 1.36) = 2.56 − 3.36
4 = 2.56 − 3 (204 − 3.56) = −3.204 + 11.56
We therefore have, 4 = − 3.204 + 11.56
Multiply by 5 since 5 × 4 = 20
20 = − 15.204 + 55.56
Upon comparison with our target we have:
gcd(204, 56) = 4, x = − 15 and y = 55
The general solution is given by:
204
x = −15 + 564 m = −15 + 14m and y = 55 − 4 m = 55 − 51m
The general solution is 20 = 204(−15 + 14m) + 56(55 − 51m)

End of topic 11 test (page 36)

Q52:
a
Start with b
382
47 =8 r=6
We have 382 = 8.47 + 6
So q = 8 and r = 6

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 53

Q53:
a
Start with b
−241
16 = −15 r = −1
We have −241 = − 15.16 + (−1)
So q = − 15 and r = − 1
But the remainder must be positive by definition of the division algorithm. Therefore, we need to
have a sufficiently small quotient to allow us to add on the remainder instead of subtracting.
In this case q = − 16
−16.6 = − 256 so to make it up to −241 we need to add on 15
We have −241 = − 16.6 + 15
So q = − 16 and r = 15

Q54:
The division algorithm is a = qb + r, where a is the dividend, q is the quotient, b the divisor and r
the remainder.
Use the division algorithm repeatedly to convert 85 10 into base 2 by reading off the answer as the
remainders in reverse order.
a = qb + r
85 = 42.2 + 1
42 = 21.2 + 0
21 = 10.2 + 1
10 = 5.2 + 0
5 = 2.2 + 1
2 = 1.2 + 0
1 = 0.2 + 1
Reading off the remainders from the bottom, the answer is 1010101 2.

Q55:
The division algorithm is a = qb + r, where a is the dividend, q is the quotient, b the divisor and r
the remainder.
Use the division algorithm repeatedly to convert 185 10 into base 8 by reading off the answer as the
remainders in reverse order.
a = qb + r
185 = 23.8 + 1
23 = 2.8 + 7
2 = 0.8 + 2
Reading off the remainders from the bottom, the answer is 271 8 .

Q56:
The division algorithm is a = qb + r, where a is the dividend, q is the quotient, b the divisor and r
the remainder.
Use the division algorithm repeatedly to convert 2354 10 into base 16 by reading off the answer as
the remainders in reverse order.

© H ERIOT-WATT U NIVERSITY
54 ANSWERS: UNIT 1 TOPIC 11

a = qb + r
2354 = 147.16 + 2
147 = 9.16 + 3
9 = 0.16 + 9
Reading off the remainders from the bottom, the answer is 932 16.

Q57:
Multiply each digit by its column heading and add the numbers together.
1.24 + 0.23 + 1.22 + 1.21 + 1.20
= 16 + 0 + 4 + 2 + 1
= 2310

Q58:
Multiply each digit by its column heading and add the numbers together.
3.43 + 2.42 + 0.41 + 1.40
= 192 + 32 + 0 + 1
= 22510

Q59:
Multiply each digit by its column heading and add the numbers together.
6.73 + 4.72 + 1.71 + 0.70
= 2058 + 196 + 7 + 0
= 226110

Q60:
Multiply each digit by its column heading and add the numbers together.
7.83 + 5.82 + 6.81 + 2.80
= 3584 + 320 + 48 + 2
= 395410

Q61:
Multiply each digit by its column heading and add the numbers together.
14.163 + 5.162 + 11.161 + 1.160
= 57344 + 1280 + 176 + 1
= 5880110

Q62:
The Euclidean algorithm uses repeated division in the form a = qb + r
The integers a and b are given and a > b. Find q and r.
Then replace a with b, and b with r to continue.

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 55

1289 = 5.233 + 124


233 = 1.124 + 109
124 = 1.109 + 15
109 = 7.15 + 4
15 = 3.4 + 3
4 = 1.3 + 1
3 = 3.1 + 0
So gcd(1289, 233) = 1

Q63:
The highest common factor is the same as gcd(36, 584)
584 = 16.36 + 8
36 = 4.8 + 4
8 = 2.4 + 0
Since gcd(36, 584) = 4, hcf(36, 584) = 4

Q64:
562 = 2.235 + 92
235 = 2.92 + 51
92 = 1.51 + 41
51 = 1.41 + 10
41 = 4.10 + 1
10 = 10.1 + 0
So gcd(235, 562) = 1

Q65:
To simplify the fraction we need to work out gcd(27, 294)
294 = 10.27 + 24
27 = 1.24 + 3
24 = 8.3 + 0
So gcd(27, 294) = 3
Since gcd(27, 294) = 3, simplify the fraction by dividing numerator and denominator by 3.
27 9
Therefore, 294 = 98 .

Q66:
The Euclidean algorithm uses repeated division in the form a = qb + r
The integers a and b are given and a > b. Find q and r.
Then replace a with b, and b with r to continue.
a = qb + r
4056 = 1.3276 + 780
3276 = 4.780 + 156
780 = 5.156 + 0
So gcd(4056, 3276) = 156

© H ERIOT-WATT U NIVERSITY
56 ANSWERS: UNIT 1 TOPIC 11

Divide the numerator and denominator by 156.


21
The answer is 26 .

Q67:
Find gcd(125, 35):
125 = 3.35 + 20
35 = 1.20 + 15
20 = 1.15 + 5
15 = 3.5 + 0
So gcd(125, 35) = 5
Working backwards from the second-last step to find one linear combination gives:
5 = 20 − 1.15
5 = 20 − (35 − 1.20)
5 = − 1.35 + 2.20
5 = − 1.35 + 2 (125 − 3.35)
5 = 2.125 − 7.35
Given 125x + 35y = gcd(125, 35), then x = 2 and y = − 7.

Q68:
First we need to find gcd(39, 51) :
51 = 1.39 + 12
39 = 3.12 + 3
12 = 4.3 + 0
So gcd(39, 51) = 3 and 3|12, therefore there is a solution.
Now, working backwards from 39 = 3.12 + 3:
3 = 39 − 3.12
3 = 39 − 3 (51 − 1.39)
3 = 4.39 − 3.51
Multiply by 4 since 4 × 3 = 12:
12 = 16.39 − 12.51
The general solution is given by:
39
x = 16 + 51
3 m = 16 + 17m and y = −12 − 3 m = −12 − 13m
The general solution is 12 = 39(16 + 17m) + 51(−12 − 13m).

Q69:
First we need to find gcd(26, 38) :
38 = 1.26 + 12
26 = 2.12 + 2
12 = 6.2 + 0
So gcd(26, 38) = 2 and 2|20, therefore there is a solution.
Now, working backwards from 26 = 2.12 + 2:

© H ERIOT-WATT U NIVERSITY
ANSWERS: UNIT 1 TOPIC 11 57

2 = 26 − 2.12
2 = 26 − 2 (38 − 1.26)
2 = 3.26 − 2.38
Multiply by 10 since 10 × 2 = 20:
20 = 30.26 − 20.38
The general solution is given by:
26
x = 30 + 38
2 m = 30 + 19m and y = −20 + 2 m = −20 − 13m
The general solution is 20 = 26(30 + 19m) + 38(−20 − 13m).

© H ERIOT-WATT U NIVERSITY

You might also like