Hello! Welcome back to our study of number theory foundations.
In our last lesson, we formalized the Division Algorithm, establishing that for any integers and (with ), there are unique integers and such that and .
Today, we will put that theorem to work. Our goal is to compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm. This elegant and efficient algorithm is a direct application of the Division Algorithm, applied repeatedly. It's a cornerstone of number theory and will be essential when we later explore the structure of modular arithmetic.
1. The Principle Behind the Algorithm
Before we learn the steps of the algorithm, let's understand why it works. The entire process is built on a single, powerful property.
The key insight is that if , then the greatest common divisor of and is the same as the greatest common divisor of and . In other words:
where is the remainder when is divided by .
To understand the reasoning behind this crucial fact, let's watch a short video that provides an accessible proof. Since you have a background in writing mathematical proofs, you should find the logic here straightforward.
EUCLIDEAN ALGORITHM - DISCRETE MATHEMATICS
The video 'EUCLIDEAN ALGORITHM - DISCRETE MATHEMATICS' from TrevTutor clearly explains and proves the fundamental property that makes the Euclidean algorithm work.
Watch the video from the beginning to 0:42 to see the statement of the property, and then from 3:51 to 7:55 for the proof. Don't worry about the specific examples for now; focus on the logic of the proof.
The proof demonstrates that:
- Any common divisor of and must also divide the remainder .
- Any common divisor of and must also divide .
This means the set of common divisors of is identical to the set of common divisors of . Consequently, their greatest common divisors must also be identical.
The Euclidean algorithm exploits this by repeatedly replacing a pair of numbers with a smaller pair that has the same GCD, until the problem becomes trivial to solve.
2. The Euclidean Algorithm in Practice
Now that we know the principle, let's see the computational procedure. We will repeatedly apply the division algorithm, where the divisor and remainder from one step become the new dividend and divisor in the next step. This process continues until we get a remainder of 0. The last non-zero remainder is our GCD.
The following video demonstrates a very clear, tabular method for organizing this process.
GCD - Euclidean Algorithm (Method 1)
The video 'GCD - Euclidean Algorithm (Method 1)' by Neso Academy shows a practical, step-by-step method for computing the GCD. Pay close attention to how the table is set up and how values are shifted in each step.
Watch from 6:38 to 12:33. The first example (gcd(12, 33)) clearly lays out the tabular method. The second example (gcd(750, 900)) reinforces the process with larger numbers.
Let's summarize the steps of the tabular method for finding , assuming :
- Set up a table with columns for the quotient (), the two numbers (let's call them and ), and the remainder ().
- In the first row, set and .
- Calculate using the Division Algorithm to find and . Fill these into the table.
- For the next row, the value of moves to the column, and the value of moves to the column.
- Repeat steps 3 and 4 until you get a remainder .
- The GCD is the value in the column of the final row (or, equivalently, the last non-zero remainder).
Let's look at a visual summary of this process.

Now, try one yourself.
Test your understanding!
Use the tabular method to find the greatest common divisor of 408 and 170.
Show answer
We want to find . Let's set up the table.
| 2 | 408 | 170 | 68 |
| 2 | 170 | 68 | 34 |
| 2 | 68 | 34 | 0 |
| - | 34 | 0 | - |
Step 1: . So .
Step 2: New pair is (170, 68). . So .
Step 3: New pair is (68, 34). . So .
The remainder is now 0. The last non-zero remainder was 34.
Therefore, .
3. A Look Ahead: The Extended Euclidean Algorithm and Code
The Euclidean algorithm is powerful in its own right, but a slight modification, known as the Extended Euclidean Algorithm, makes it even more useful. This extended version not only finds the GCD, , but also finds two integers, and , such that:
This ability to express the GCD as a linear combination of the original two numbers is fundamental. We will use this exact technique later in the course to find multiplicative inverses in .
You don't need to master the extended algorithm today, but it's valuable to see that it exists and how it relates to our current topic. Since you have an interest in coding, looking at a practical implementation can be a great way to solidify your understanding of the standard algorithm as well.
The document 'The Euclidean Algorithm' from the University of Alberta formalizes the algorithm and introduces the extended version. It also includes a C code implementation, which directly ties into your interest in coding.
First, read the section 'The Euclidean Algorithm' on the first page to see the formal sequence of equations. Then, read the first two paragraphs on the second page (starting with 'This is Euclid’s algorithm...') to understand the concept of the extended algorithm. Finally, look at the C code implementation on the third page. Try to trace how the while loop corresponds to the repeated subtractions/divisions we've been doing.
The C code provides a concrete example of how this seemingly abstract process is implemented algorithmically, reducing it to a series of simple arithmetic operations and comparisons.
Conclusion
In this lesson, we demystified one of the oldest and most important algorithms in mathematics.
Key Takeaways:
- The Euclidean algorithm is an efficient method for computing the greatest common divisor (GCD) of two integers.
- It relies on the principle that .
- The algorithm works by repeatedly applying the Division Algorithm until a remainder of 0 is reached. The GCD is the last non-zero remainder.
- The Extended Euclidean Algorithm can express the GCD as a linear combination , a fact that will be crucial later on.
Preview of the Next Lesson:
We will now move from divisibility to the related concept of modular congruence. We will define what it means for two numbers to be "congruent modulo n" and start performing arithmetic with these congruences. This is our first step into a new algebraic system, , where the ideas of remainders and GCDs will play a central role.