11 Euclids-Algorithm
11 Euclids-Algorithm
Authored by:
Fiona Withey (Stirling High School)
Karen Withey (Stirling High School)
Reviewed by:
Margaret Ferguson
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.
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
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 3
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
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:
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 5
Key point
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
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
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
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.
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}
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.
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
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
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.
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.
© 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.
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
"Mathematics is the queen of sciences and number theory is the queen of mathematics."
Carl Gauss (1777 - 1855)
© H ERIOT-WATT U NIVERSITY
14 TOPIC 11. EUCLID'S ALGORITHM
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 15
Key point
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
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
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.
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
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 17
...............................................
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.
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.
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
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 .
© 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
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 + .
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.
Q33: Use the Euclidean algorithm to show that 10465 and 5643 are relatively prime.
...............................................
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 23
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
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
Key point
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.
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
Key point
© 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
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.
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
...............................................
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
Q50: Find the general solution of the equation gcd(585, 104) = 585x + 104y using the
Euclidean algorithm.
...............................................
© H ERIOT-WATT U NIVERSITY
TOPIC 11. EUCLID'S ALGORITHM 29
• 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 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
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
© 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}
© 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)
© H ERIOT-WATT U NIVERSITY
34 TOPIC 11. EUCLID'S ALGORITHM
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.
© 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
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
© 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 .
© 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
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
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.
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
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.
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
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.
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
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
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
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
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)
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
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
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