Difference between revisions of "Euclidean algorithm"
(→Linear Representation) |
(→Example) |
||
Line 30: | Line 30: | ||
== Example == | == Example == | ||
− | To see how it works, just take an example. Say <math>a= | + | To see how it works, just take an example. Say <math>a = 93, b=42</math>. <br/> |
− | We have <math> | + | We have <math>93 \equiv 9 \pmod{42}</math>, so <math>\gcd(93,42) = \gcd(42,9)</math>. <br/> |
− | Similarly, <math>42\equiv | + | Similarly, <math>42 \equiv 6 \pmod{9}</math>, so <math>\gcd(42,9) = \gcd(9,6)</math>. <br/> |
− | <br />Then <math> | + | Continuing, <math>9 \equiv 3 \pmod{6}</math>, so <math>\gcd(9,6) = \gcd(6,3)</math>. <br/> |
− | Thus <math>\gcd( | + | Then <math>6 \equiv 0 \pmod{3}</math>, so <math>\gcd(6,3) = \gcd(3,0) = 3</math>. <br/> |
+ | Thus <math>\gcd(93,42) = 3</math>. | ||
− | * <math> | + | * <math>93 = 2 \cdot 42 + 9 \qquad (1)</math> |
− | * <math>42 = 1\cdot | + | * <math>42 = 4 \cdot 9 + 6 \qquad (2)</math> |
− | * <math> | + | * <math>9 = 1 \cdot 6 + 3 \qquad (3)</math> |
+ | * <math>6 = 2 \cdot 3 + 0 \qquad (4)</math> | ||
== Extended Euclidean Algorithm == | == Extended Euclidean Algorithm == |
Revision as of 13:52, 26 September 2015
The Euclidean algorithm (also known as the Euclidean division algorithm or Euclid's algorithm) is an algorithm that finds the greatest common divisor (GCD) of two elements of a Euclidean domain, the most common of which is the nonnegative integers , without factoring them.
Contents
[hide]Main idea and Informal Description
The basic idea is to repeatedly use the fact that
If we have two non-negative integers with and , then the greatest common divisor is . If , then the set of common divisors of and is the same as the set of common divisors of and where is the remainder of division of by . Indeed, we have with some integer , so, if divides both and , it must divide both and and, thereby, their difference . Similarly, if divides both and , it should divide as well. Thus, the greatest common divisors of and and of and coincide: . But the pair consists of smaller numbers than the pair ! So, we reduced our task to a simpler one. And we can do this reduction again and again until the smaller number becomes
General Form
Start with any two elements and of a Euclidean Domain
- If , then .
- Otherwise take the remainder when is divided by , and find .
- Repeat this until the remainder is 0.
Then
Usually the Euclidean algorithm is written down just as a chain of divisions with remainder:
for
and so
Example
To see how it works, just take an example. Say .
We have , so .
Similarly, , so .
Continuing, , so .
Then , so .
Thus .
Extended Euclidean Algorithm
An added bonus of the Euclidean algorithm is the "linear representation" of the greatest common divisor. This allows us to write , where are some elements from the same Euclidean Domain as and that can be determined using the algorithm. We can work backwards from whichever step is the most convenient.
Continuing the previous example, our goal is to find and such that We can work backwards from equation since appears there: We currently have as a linear combination of and . Rearranging to , we can substitute to express as a linear combination of and :
Continuing, we rearrange to substitute :
Furthermore, since , dividing both sides by gives . We can add times this equation to , so we can write as a linear combination of and
for any integer .