1.7: The Euclidean Algorithm
- Page ID
- 82289
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)Unlike the Division Algorithm, the Euclidean Algorithm really is an algorithm. It provides a method to compute \(\gcd(a,b)\). Since as already noted \(\gcd(0,0)=0\), \(\gcd(a,b)=\gcd(|a|,|b|)\), and \(\gcd(a,b) = \gcd(b,a)\), it suffices to give a method to compute \(\gcd(a,b)\) when \(a\ge b\ge 0\).
If \(a>0\), then \(\gcd(a,0)=a\).
- Proof
-
Since every integer divides \(0\), \(C(a,0)\) is just the set of divisors of \(a\). By Lemma 6.2 the largest divisor of \(a\) is \(|a|\). Since \(a>0\), \(|a|=a\). This shows that \(\gcd(a,0)=a\).
Remark \(\PageIndex{1}\)
So we are now reduced to the problem of finding \(\gcd(a,b)\) when \(a\ge b>0\).
Now having done Exercise \(\PageIndex{1}\) we only need to consider the case \(a>b>0\).
Let \(a>b>0\). If \(a=bq+r\), then \[\gcd(a,b)=\gcd(b,r).\nonumber\]
- Proof
-
It suffices to show that \(C(a,b)=C(b,r)\), that is, the common divisors of \(a\) and \(b\) are the same as the common divisors of \(b\) and \(r\). To show this first let \(d\mid a\) and \(d\mid b\). Note that \(r=a-bq\), which is a linear combination of \(a\) and \(b\). So by Theorem 3.1(3) \(d\mid r\). Thus \(d\mid b\) and \(d\mid r\). Next assume \(d\mid b\) and \(d\mid r\). Using Theorem 3.1(3) again and the fact that \(a=bq+r\) is a linear combination of \(b\) and \(r\), we have \(d\mid a\). So \(d\mid a\) and \(d\mid b\). We have thus shown that \(C(a,b)=C(b,r)\). So \(\gcd(a,b)=\gcd(b,r)\).
Remark \(\PageIndex{2}\)
The Euclidean Algorithm is the process of using Lemmas \(\PageIndex{2}\) and \(\PageIndex{1}\) to compute \(\gcd(a,b)\) when \(a>b>0\).
Rather than give a precise statement of the algorithm I will give an example to show how it goes.
Example \(\PageIndex{1}\)
Let’s compute \(\gcd(803,154)\).
\[\begin{aligned} \gcd(803,154) &=\gcd(154,33) \quad \mbox{ since } 803 =154\cdot5+33 \\ \gcd(154,33) &=\gcd(33,22) \quad \mbox{ since } 154 =33\cdot4+22 \\ \gcd(33,22) &=\gcd(22,11)\quad \mbox{ since } 33 =22\cdot1+11 \\ \gcd(22,11) &=\gcd(11,0) \quad \mbox{ since } 22 =11\cdot2+0 \\ \gcd(11,0) &= 11. \end{aligned}\] Hence \(\gcd(803,154)=11\).
Remark \(\PageIndex{3}\)
Note that we have formed the \(\gcd\) of \(803\) and \(154\) without factoring \(803\) and \(154\). This method is generally much faster than factoring and can find \(\gcd\)’s when factoring is not feasible.
Exercise \(\PageIndex{2}\)
Let \(a>b>0\). Show that \(\gcd(a,b)=\gcd(b, a \bmod b)\).
Remark \(\PageIndex{4}\)
So if your calculator can compute \(a\bmod b\) you may use it when executing the Euclidean Algorithm.
Exercise \(\PageIndex{3}\)
Find \(\gcd(a,b)\) using the Euclidean Algorithm for each of the values below:
- \(a=37\), \(b=60\)
- \(a=793\), \(b=3172\)
- \(a=25174\), \(b=42722\)
- \(a=377\), \(b=233\)