Although it is easy to see that the greatest common divisor of 5 and 2 is 1, we need some of the intermediate result from the Euclidean algorithm to find
\(s\) and
\(t\text{.}\) Following the Euclidean algorithm (
Algorithm 4.17) for the input values
\(a:=5\) and
\(b:=2\) we get:
Input |
|
\(5\) |
\(2\) |
(1) |
\(5\fmod 2=1\) |
\(2\) |
\(1\) |
(1) |
\(2\fmod 1=0\) |
\(1\) |
\(0\) |
Output |
|
1 |
We have confirmed that
\(\gcd(5,2)=1\text{.}\) Since the Euclidean algorithm terminated after 2 iterations we can use the same trick as in
Example 4.26. We get
\begin{equation*}
r := 5 \fmod 2 = 1
\end{equation*}
and
\begin{equation*}
q := 5 \fdiv 2 = 2
\end{equation*}
Plugging these into the formula
\begin{equation*}
(1 \cdot a) + ((-q) \cdot b) = r
\end{equation*}
we get
\begin{equation*}
(1 \cdot 5) + ((-2) \cdot 2) = 1\text{.}
\end{equation*}
We read of the values \(s:=1\) and \(t:=-2\text{.}\) Note that \(t=-(5 \fdiv 2)\text{.}\)