next up previous contents
Next: Modular Arithmetic Up: Euclid's Algorithm Previous: Example

Formula

Start with positive integers a<m. In formulas, Euclid's algorithm looks like the following:

\begin{displaymath}\begin{array}{ccccccc\vert c\vert c}
&&&&&&&0&1\\
\text{Di...
... &=&q_{n+1} &\cdot &r_n &+& 0 &h_{n+1}&k_{n+1} \\
\end{array}\end{displaymath}

Subscripts are used to indicate the order in which the numbers appear. For instance, q1, q2, ..., is the sequence of quotients.

The remainders form a sequence, too, with r-1=m, r0=a, r1, r2, ..., rn+1=0. Because the remainder is always less than the divisor, these form a strictly decreasing sequence

\begin{displaymath}r_{-1} > r_0 > r_1> r_2>\dots > r_n >0=r_{n+1}
\end{displaymath}

The formula for the h's and k's are as follows:
\begin{align*}h_{l} & = q_l \, h_{l-1} + h_{l-2} \\ [3pt]
k_{l} & = q_l \, k_{l-1} + k_{l-2} \\ [3pt]
\end{align*}
This is called a two-term recurrence, because to get the next term in the sequence, we have to use the previous two terms.

At every step in Euclid's algorithm we have

\begin{displaymath}h_j \,a - k_j\, m = (-1)^j r_j
\end{displaymath}

j is a subscript indicating which step we are at. The power (-1)jis -1 times itself j times; hence, it is +1 if j is even and -1 if j is odd.

Therefore the very last nonzero remainder, which is the smallest, satisfies

\begin{displaymath}h_n \,a - k_n\, m = (-1)^n r_n
\end{displaymath}

That last nonzero remainder rn is the greatest common divisor of aand m. If it turns out to be 1, then our equation says

\begin{displaymath}h_n a \equiv (-1)^n \pmod m
\end{displaymath}

after discarding the multiple of m. That's why the solution to $a\, x \equiv 1 \pmod{m}$ is x= (-1)n hn, or hn if n is even and -hn if n is odd.


next up previous contents
Next: Modular Arithmetic Up: Euclid's Algorithm Previous: Example
David J. Wright
2000-09-11