Wheelock College Technology
Course
Euclid’s Algorithm: Debbie
Borkovitz
May 2001
Explorations
For
the explorations portion of the workshop, you can choose your own starting
point. If you are new to Excel and/or
you are nervous about the mathematics, I suggest you start with the
tutorial. Otherwise, feel free to jump
right to the suggested activities (or to suggest your own and do it…).
Tutorial:
1) First,
do Euclid’s Algorithm by hand (or
using a calculator) to find the greatest common factor of 219 and 123. Write out every step. Your answer should be 3. Be sure you’re clear on this step before you
start using the computer.
2) Start up
Excel. You will see a screen with lots
of rectangular boxes. This is a
worksheet. The columns are labeled with
letters and the rows with numbers. Each
rectangular box is called a cell.
The cells are denoted A1, C17, etc. (C17 is a cell in column C, row 17
etc.). You can enter numbers, text, formulas, etc. into each cell.
3) In each
row, we will represent one subtraction step in the algorithm. We don’t actually have to type very much to
make the table; most of it is automatic. We will place the larger number in
column A, the smaller number in column B, and the difference in column C. Start labeling each column by typing
something like “larger number” in cell A1.
Don’t type the quotes, and hit return when you are done. You probably will not have enough space, so
you need to make column A wider. To do
this, move the mouse to the gray area at the top of the worksheet, on the line
between letters A and B. When you are in
the right place, the cursor will change from a white cross to a black vertical
line with horizontal arrows through it.
Now you can drag to change the widths manually or double click to change
them automatically. Label columns B and
C by typing in cells B1 and C1.
4) We will
start by having Excel do Euclid’s
algorithm using 219 and 123. Later, you
can change a few values and the whole table will update automatically. Type 219 in cell A2 and 123 in cell B2.
5) Now, we
want cell C2 to be 219-123. However,
instead of typing the actual number, we will use a formula that references
individual cells. In a short while,
you’ll see the power of using such a formula.
In cell C2, start by typing an equal sign (=). Formulas always start with equal signs, and
forgetting the equal sign is a common (easily corrected) mistake. Now either type A2-B2 or else click in A2
then type a minus sign and click in B2 (i.e. instead of typing cell references,
you can just click in the cell
if you make a mistake doing this, type Esc and
start over). Type return. You should see 96 in cell C2. Excel does the subtraction automatically.

6) Now
we’ll start on the second row of our table.
This is the last row in which we’ll have to type anything! Now, we need new numbers to go into cells A3
and B3 so we can compute the next row.
We know that 96 is smaller than 123, however, it is possible for the
number in C2 to be larger than the number in B2 (you might wish to check your
handwritten example for rows where the difference is larger than the smaller of
the initial numbers). In cell A3, we
wish to put the larger of B2 and C2. We
don’t know which one it will be, but we don’t need to: Excel has a command
called max that finds the maximum value of two numbers. In cell A3, type “=max(B2,C2).” Don’t type the quotes or the period, and you
can click in the cells instead of typing them.
Hit return. Now use the analogous
“min” command in cell B3. You should see
the appropriate numbers in each cell.
7) Now
click on cell C2. Notice that in the
bottom right corner of the cell there’s a little black box. This is called a fill handle. Move the cursor to this little black
box. The cursor will change to a black
cross. Hold down the left mouse button
and drag the cursor down one cell. Let
go. Cell C3 should show 27, which is
A3-B3. Click on cell C3. If you look up above the worksheet, you will
see the formula bar, which displays the actual formula used to calculate
each cell. Note that the formula has
changed automatically from A2-B2 to A3-B3 (also click in C2 to see the
difference).
8) Now comes the fun part! Click in cell A3 hold down the mouse button
and drag to cell C3. You should see an
outline around all three cells, with the right two shaded. Note the fill handle at the bottom right
corner. Drag this fill handle down as
many rows as you wish (at least 10). You
should see an entire table, pretty much like the one you did by hand. Click in various cells, look at the formula
bar, and see how Excel has changed the formulas automatically.
9) Now
comes the other fun part. Change the
numbers in A2 and B2. The whole table
should change automatically. You might
have to drag the formulas down more cells, but otherwise, you now have a
program for executing Euclid’s
algorithm for any two natural numbers.
10) If
there’s time, go on to one of the suggested activities below.
Suggested Activities (Start wherever you wish):
1. Use multiplication and division to reformulate Euclid’s
Algorithm and make it less tedious.
2. Design a spreadsheet that implements Euclid’s
Algorithm (either version). If you
already did the tutorial, find a different way to implement the
spreadsheet. Some commands you might
find useful include: int, mod, min, max.
3. Explore other things to do with Excel.
4. Bezout’s theorem is important in Number Theory. It states that if d is the greatest common
divisor of a and b, then there are integers x and y such that ax+by=d. For example, the greatest common divisor of
219 and 123 is 3 and 
. It is not obvious how to find x and y, but
(as you might guess), Euclid’s
Algorithm (done kind of backwards) makes it much easier. Explore Bezout’s theorem. Can you find integers x and y so that 
? Can you find a way to use a spreadsheet as a
tool in solving equations such as this one?
(By the way, equations whose solutions must be integers are called Diophantine
Equations).
Wheelock College
Technology Course
Euclid’s Algorithm: Debbie
Borkovitz
May 2001
Background
The Distributive Property:
The
distributive property is key to why Euclid’s
Algorithm works. Below it is illustrated
with a specific example. Think about how
to generalize this example.
3 is a factor of 18 (or we say 3 divides 18)
because 18 ÷3 has no remainder.
Visually, we can represent 18 as groups of 3:
As an equation, we have 
.
Now, 3 is also a factor of 12, because 12 ÷3 has no remainder. Visually we have,
and as an equation we have, 
.































Now, the
distributive property tells us that 3 is a factor of both 18+12 and of
18-12. Visually, we see that 18+12 can be
written as 6+4=10 groups of 3:
As an equation, we have 
.
Similarly, 18-12 can be written as 6-4=2 groups of 3:
As an equation, we have 
.
For understanding Euclid’s
Algorithm, the important consequence of the distributive property is that if f
is a factor of both a and b, then f is a factor of both a+b and of a-b.
An Illustration of Euclid’s
Algorithm:
We will
find the greatest common factor of 72 and 30.
The greatest common factor is exactly what it sounds like: it is
the largest natural number (i.e. whole number) that is a factor of both 30 and
72.
By the
distributive property, we know that any factor of both 72 and 30 is also a
factor of 72-30=42.
Similarly,
any factor of both 30 and 42 is also a factor of 42-30=12 (and thus, any factor
of both 72 and 30 is also a factor of 12).
Continuing
in this manner, any factor of both 30 and 12 is also a factor of
30-12=18.
Any factor
of both 18 and 12 is also a factor of 18-12=6.
Any factor
of both 12 and 6 is also a factor of 12-6=6.
Now we are
left with 6 and 6. Following the entire
chain of reasoning above, any factor of both 72 and 30 must also be a factor of
6.
Now, the
greatest factor of 6 is 6 itself. So, if
we can show that 6 must be a factor of 30 and 72, then 6 must be the greatest
common factor of 30 and 72. Of course, 6
is a factor of both 30 and 72, but to use this example to illustrate how to
prove that Euclid’s Algorithm works
in general, we note that we can use the distributive property looking at the
algorithm backwards. Since 6 is a
factor of both 6 and 6, it is a factor of 6+6=12. Since 6 is a factor of 6 and of 12, it is a
factor of 6+12=18, etc. Continuing this
way, we see that 6 is a factor of both 30 and 72, hence it is the greatest
common factor.
Copyright 2005, Debra K. Borkovitz.
You may copy or edit this material for non-profit, educational use only.
To Commentary
Doc File
PDF File
Home