next up previous
Next: Powering Algorithm Up: Important Algorithms Previous: Important Algorithms

Euclid's Algorithm

Given integers $ a$ and $ b$, a slight extension of Euclid's gcd algorithm enables us to find integers $ x$ and $ y$ such that

$\displaystyle ax + by = \gcd(a,b).
$

Example 6.1   $ a=12$, $ b=101$.

$\displaystyle \underline {101}$ $\displaystyle =8\cdot \underline {12} + \underline {5}$ $\displaystyle \underline {5}$ $\displaystyle =\underline {101}-8\cdot \underline {12}$    
$\displaystyle \underline {12}$ $\displaystyle =2\cdot\underline {5} + \underline {2}$ $\displaystyle \underline {2}$ $\displaystyle = -2\cdot \underline {101} + 17\cdot \underline {12}$    
$\displaystyle \underline {5}$ $\displaystyle =2\cdot \underline {2}+ \underline {1}$ $\displaystyle \underline {1}$ $\displaystyle = \underline {5} - 2\cdot \underline {2} = 5\cdot \underline {101} - 42\cdot \underline {12}.$    

Thus $ x=-42$, $ y=5$ works, and $ \gcd(a,b)=1$.

We can use the result of this computation to solve

$\displaystyle 12x\equiv 1\pmod{101}.$

Indeed, $ 1=(-42)\cdot 12 + 5\cdot 101$, so $ x=-42$ is a solution.



William A Stein 2001-10-14