Interactive · 2 questions
Recall that the Greatest Common Divisor (gcd) of two integers A and B is the largest integer that divides both A and B.
The Euclidean Algorithm is a technique for quickly finding the of two integers.
The Algorithm
The Improved Euclidean Algorithm is based on a simple theorem: and a little lemma
where means the quotient remainder of B when taking modulus of A.
The Euclidean Algorithm for finding for positive integers A, B is as follows:
- If A = 0 then , and we can stop.
- If B = 0 then , and we can stop.
- Otherwise, write as , where is an integer and . According to the theorem above, , where .
What if these steps keeps recurring without giving us an answer?
Don't worry, the algorithm must terminate at some step.
The sum of the two numbers in parenthesis, which is a positive integer, can't decrease forever. Remember part of the [definition of an integer] is that it is made up of finitely many s? When we say , the difference between and must be a positive integer, so we have took at least from in this step. We can only take s from A+B for finitely many times, so the algorithm always terminates.
Example: Finding the GCD of 270 and 192
A=270, B=192
Step 1: Check that A ≠ 0
Step 2: Check that B ≠ 0
Step 3: Use long division to find that 270/192 = 1 with a remainder of 78. We can write this as: The original problem is reduced to: Find , since =
A=192, B=78
Step 1: Check that A ≠ 0
Step 2: Check that B ≠ 0
Step 3: Use long division to find that 192/78 = 2 with a remainder of 36. We can write this as: The original problem is reduced to: Find , since =
A=78, B=36
Step 1: Check that A ≠ 0
Step 2: Check that B ≠ 0
Step 3: Use long division to find that 78/36 = 2 with a remainder of 6. We can write this as: The original problem is reduced to: Find , since =
A=36, B=6
What is our next step after checking that A ≠ 0 and B ≠ 0?
We can write this as: The original problem is reduced to: Find , since =
A=6, B=0
Step 1: Check that A ≠ 0
Step 2: B = 0, therefore =6
So we have shown:
= = = = = 6
= 6
Exploration: Why does this work?
To prove this algorithm, we will prove the lemma and the theorem.
Let's start from the lemma. Why does ?
What does gcd(A,B) mean in words?
... And we know means the greatest common divisor of B and A. In the language of logic, "A and B" is the same as "B and A". Therefore .
Why does ?
Here, it is more convenient to write as , when . Why does such always exist.
If an integer divides both and , we can write and as multiples of , and , where and are integers. Therefore, d is a divisor of , hence a common divisor of and . Similarly, any common divisor of and would be a common divisor of and . They must equal.
Why is this called an "improved" Euclidean Algorithm?
In the version where the third step is (WLOG take ). For some numbers the third step makes a huge difference.
Suppose we are to find .
- Algorithm version 1.0: we get . The sum of the numbers in parenthesis decreased a little.
- Improved algorithm: We get . That's a lot smaller!