Given some a and b, how do we actually find s and t? The above proof is not much help: it merely shows s and t must exist, but does not actually show us how to find them. Fortunately, there is an efficient procedure for doing so, known as the Extended Euclidean Algorithm.
Let’s take a = 60, b = 18 as an example. We begin by making a table with three columns labelled s, t, 60s + 18t. In the first row we set s = 1 and t = 0; in the second row we do the reverse. The value in the third column should always be the corresponding value of the expression 60s + 18t.
\begin {array}{ccc}
s & t & 60s + 18t \\ \hline
1 & 0 & 60 \\
0 & 1 & 18
\end {array}
Of course, 60 \cdot 1 + 18 \cdot 0 = 60, and 60 \cdot 0 + 18 \cdot 1 = 18, so we fill in these values in the third column.
The idea is that we are going to run the Euclidean Algorithm on the values in the third column, but along the way, we are going to keep track of the values of s and t that generate each. If we were running the Euclidean Algorithm to compute \gcd (60,18), our first step would be to replace (60, 18) by (18, 6) (since 60 \mathbin {\mathbf {mod}} 18 = 6). So we place a 6 in the third column under the 18:
\begin {array}{ccc}
s & t & 60s + 18t \\ \hline
1 & 0 & 60 \\
0 & 1 & 18 \\
& & 6
\end {array}But what should we put in the first two columns? The key is to think about how we get 6 from 60 and 18. We get the remainder 6 by subtracting some number of copies of 18 from 60: in fact, we subtract 60 \mathbin {\mathbf {div}} 18 = 3 copies of 18. The big insight is that we can do exactly the same operation in each of the first two columns, namely, subtract three times the bottom value from the top value. In general, if 60s_1 + 18t_1 = x and 60s_2 + 18t_2 = y, then x - qy = (60s_1 + 18t_1) - q(60s_2 + 18t_2) = 60(s_1 - qs_2) + 18(t_1 -
qt_2). So we put 1 - 3\cdot 0 = 1 in the first column and 0 - 3
\cdot 1 = -3 in the second column:
\begin {array}{ccc}
s & t & 60s + 18t \\ \hline
1 & 0 & 60 \\
0 & 1 & 18 \\
1 & -3 & 6
\end {array}
And indeed, we can verify that 60 \cdot 1 + 18 \cdot (-3) = 6.
If we proceed one more step, we find that 18 \mathbin {\mathbf {mod}} 6 = 0, which means that 6 is actually the \gcd of 60 and 18, and we have found the coefficients s and t we were looking for.
\begin {array}{ccc}
s & t & 60s + 18t \\ \hline
1 & 0 & 60 \\
0 & 1 & 18 \\
1 & -3 & 6 \\
& & 0
\end {array}