Difference between revisions of "Euclidean algorithm"
m (proofreading) |
(reorganized) |
||
Line 1: | Line 1: | ||
− | The Euclidean algorithm allows to find the [[greatest common divisor]] of any two | + | The '''Euclidean algorithm''' allows us to find the [[greatest common divisor]] of any two [[nonnegative]] [[integer]]s. |
− | + | ||
− | To see how it works, just take an example <math>\displaystyle a=112 | + | == Steps == |
− | Usually the Euclidean algorithm is written down just as a chain of divisions | + | |
− | + | Start with two nonnegative integers, <math>{a}</math> and <math>b</math>. | |
− | <math>112=2\cdot 42+ 28</math> | + | |
− | + | * If <math>b=0</math>, then <math>\gcd(a,b)=a</math>. | |
− | <math>42=1\cdot 28+14</math> | + | * Otherwise take the [[remainder]] when <math>{a}</math> is divided by <math>b</math> (<math>{a}\pmod {b}</math>), and find <math>\gcd(b,a\pmod {b})</math>. |
− | + | ||
− | <math>28=2\cdot 14+0</math> | + | Repeat this until <math>b=0</math>. |
− | + | ||
− | + | == Simple Example == | |
− | + | ||
− | <math> | + | To see how it works, just take an example. Say <math>\displaystyle a=112,b=42</math>. We have <math>112\equiv 28\pmod {42}</math>, so <math>\displaystyle{\gcd(112,42)}=\displaystyle\gcd(42,28)</math>. Similarly, <math>42\equiv 14\pmod {42}</math>, so <math>\displaystyle\gcd(42,28)=\displaystyle\gcd(28,14)</math>. Then <math>28\equiv {0}\pmod {14}</math>, so <math>{\displaystyle \gcd(28,14)}={\displaystyle \gcd(14,0)} = 14</math>. Thus <math>\displaystyle\gcd(112,42)=14</math>. |
− | + | ||
− | + | Usually the Euclidean algorithm is written down just as a chain of divisions: | |
− | <br> | + | |
− | + | * <math>{\displaystyle 112 = 2 \cdot 42 + 28 \qquad (1)}</math> | |
− | == | + | * <math>42 = 1\cdot 28+14\qquad (2)</math> |
− | * | + | * <math>28 = 2\cdot 14+0\qquad (3)</math> |
+ | |||
+ | == Linear Representation == | ||
+ | |||
+ | An added bonus of the Euclidean algorithm is the "linear representation" of the greatest common divisor. This allows us to write <math>\gcd(a,b)=ax+by</math>, where <math>x,y</math> are constants to be determined. | ||
+ | |||
+ | In the example, we can rewrite equation <math>(2)</math> from above as | ||
+ | |||
+ | <math>14 = 42-1\cdot 28</math><br> | ||
+ | <math>14 = 42-1\cdot (112-2\cdot 42)</math><br> | ||
+ | <math>14 = 3\cdot 42-1\cdot 112.</math><br> | ||
+ | |||
+ | == Examples == | ||
+ | |||
+ | * [http://www.artofproblemsolving.com/Forum/resources.php?c=182&cid=45&year=1985&p=453677 AIME 1985/13] |
Revision as of 13:24, 19 June 2006
The Euclidean algorithm allows us to find the greatest common divisor of any two nonnegative integers.
Steps
Start with two nonnegative integers, and .
- If , then .
- Otherwise take the remainder when is divided by (), and find .
Repeat this until .
Simple Example
To see how it works, just take an example. Say . We have , so . Similarly, , so . Then , so . Thus .
Usually the Euclidean algorithm is written down just as a chain of divisions:
Linear Representation
An added bonus of the Euclidean algorithm is the "linear representation" of the greatest common divisor. This allows us to write , where are constants to be determined.
In the example, we can rewrite equation from above as