next up previous
Next: Numbers Do Factor Up: Greatest Common Divisors Previous: Greatest Common Divisors

Euclid's Algorithm for Computing GCDs

Can we easily compute something like $ \gcd(2261,1275)$? Yep. Watch closely:

$\displaystyle 2261 = 1\cdot 1275 + 986.$

Notice that if a number $ d$ divides both $ 2261$ and $ 1275$, then it automatically divides $ 986$, and of course $ d$ divides $ 1275$. Also, if a number divides both $ 1275$ and $ 986$, then it has got to divide $ 2261$ as well! So we have made progress:

$\displaystyle \gcd(2261,1275) = \gcd(1275,986)$

Let's try again:

$\displaystyle 1275 = 1\cdot 986 + 289,$

so $ \gcd(1275,986)=\gcd(986,289)$. Just keep at it:

$\displaystyle 986$ $\displaystyle =3\cdot 289 + 119$    
$\displaystyle 289$ $\displaystyle =2\cdot 119 + 51$    
$\displaystyle 119$ $\displaystyle =2\cdot 51 + 17.$    

Thus $ \gcd(2261,1275)=\cdots=\gcd(51,17)$, which is $ 17$ because $ 17\mid 51$, so

$\displaystyle \gcd(2261,1275)=17.$

Cool. Aside from tedious arithmetic, that was quick and very mechanical.



The Algorithm: That was an illustration of Euclid's algorithm. You just ``Divide and switch.''

More formally, fix $ a, b\in\mathbf{N}$ with $ a>b$. Using ``divide with quotient and remainder'', write $ a=bq+r$, with $ 0\leq r<b$. Then, just as above,

$\displaystyle \gcd(a,b) = \gcd(b,r).$

Let $ a_1=b$, $ b_1=r$, and repeat until $ r=0$. Soon enough we have computed $ \gcd(a,b)$.

Here's are two more examples:

Example 2.2   Set $ a=15$ and $ b=6$.
$\displaystyle 15$ $\displaystyle =$ $\displaystyle 6\cdot 2 + 3 \qquad\gcd(15,6)=\gcd(6,3)$  
$\displaystyle 6$ $\displaystyle =$ $\displaystyle 3\cdot 2 + 0 \qquad\gcd(6,3) =\gcd(3,0)=3$  

We can just as easily do an example that is ``$ 10$ times as hard'':

Example 2.3   Set $ a=150$ and $ b=60$.
$\displaystyle 150$ $\displaystyle =$ $\displaystyle 60\cdot 2 + 30 \qquad\gcd(150,60)=\gcd(60,30)$  
$\displaystyle 60$ $\displaystyle =$ $\displaystyle 30\cdot 2 + 0 \qquad\,\,\,\gcd(60,30) =\gcd(30,0)=30$  

With Euclid's algorithm in hand, we can prove that if a prime divides the product of two numbers, then it has got to divide one of them. This result is the key to proving that prime factorization is unique.

Theorem 2.4 (Euclid)   Let $ p$ be a prime and $ a, b\in\mathbf{N}$. If $ p\mid ab$ then $ p\mid a$ or $ p\mid b$.

Proof. If $ p\mid a$ we are done. If $ p\nmid a$ then $ \gcd(p,a)=1$, since only $ 1$ and $ p$ divide $ p$. Stepping through the Euclidean algorithm from above, we see that $ \gcd(pb,ab) = b.$ At each step, we simply multiply the equation through by $ b$. Since $ p\mid pb$ and, by hypothesis, $ p\mid ab$, it follows that $ p\mid \gcd(pb,ab) = b$. $ \qedsymbol$


next up previous
Next: Numbers Do Factor Up: Greatest Common Divisors Previous: Greatest Common Divisors
William A Stein 2001-09-14