next up previous
Next: To solve Up: How to Solve Previous: How to Solve

More About GCDs

Proposition 1.1   Suppose $ a,b\in\mathbb{Z}$ and $ \gcd(a,b)=d$. Then there exists $ x,y\in\mathbb{Z}$ such that

$\displaystyle ax + by = d.
$

I won't give a formal proof of this proposition, though there are many in the literature. Instead I will show you how to find $ x$ and $ y$ in practice, because that's what you will need to do in order to solve equations like $ ax\equiv 1\pmod{n}$.

Example 1.2   Let $ a=5$ and $ b=7$. The steps of the Euclidean $ \gcd$ algorithm are:

$\displaystyle \underline{7}$ $\displaystyle =1\cdot \underline{5} + \underline{2}$ so $\displaystyle \underline{2}$ $\displaystyle = \underline{7} - \underline{5}\hfill$    
$\displaystyle \underline{5}$ $\displaystyle =2\cdot \underline{2} + \underline{1}$ so $\displaystyle \underline{1}$ $\displaystyle = \underline{5} - 2\cdot \underline{2} = 3\cdot\underline{5}-2\cdot\underline{7}\hfill$    

On the right, we have written each partial remainder as a linear combination of $ a$ and $ b$. In the last step, we write $ \gcd(a,b)$ as a linear combination of $ a$ and $ b$, as desired.

That example wasn't too complicated, next we try a much longer example.

Example 1.3   Let $ a=130$ and $ b=61$. We have

$\displaystyle \underline{130}$ $\displaystyle = 2\cdot \underline{61} + \underline{8}$ so $\displaystyle \underline{8}$ $\displaystyle = \underline{130}-2\cdot\underline{61}$    
$\displaystyle \underline{61}$ $\displaystyle = 7\cdot \underline{8} + \underline{5}$ so $\displaystyle \underline{5}$ $\displaystyle = -7\cdot\underline{130}+15\cdot\underline{61}$    
$\displaystyle \underline{8}$ $\displaystyle = 1\cdot \underline{5} + \underline{3}$ so $\displaystyle \underline{3}$ $\displaystyle = 8\cdot\underline{130}-17\cdot\underline{61}$    
$\displaystyle \underline{5}$ $\displaystyle = 1\cdot \underline{3} + \underline{2}$ so $\displaystyle \underline{2}$ $\displaystyle =-15\cdot\underline{130}+32\cdot\underline{61}$    
$\displaystyle \underline{3}$ $\displaystyle = 1\cdot \underline{2} + \underline{1}$ so $\displaystyle \underline{1}$ $\displaystyle = 23\cdot\underline{130}-49\cdot\underline{61}$    

Thus $ x=130$ and $ y=-49$.

Remark 1.4   For our present purposes it will always be sufficient to find one solution to $ ax+by=d$. In fact, there are always infinitely many solutions. If $ x, y$ is a solution to

$\displaystyle ax + by = d,
$

then for any $ \alpha\in\mathbb{Z}$,

$\displaystyle a\left(x+\alpha\cdot\frac{b}{d}\right) + b\left(y - \alpha\cdot\frac{a}{d}\right) = d,
$

is also a solution, and all solutions are of the above form for some $ \alpha$.

It is also possible to compute $ x$ and $ y$ using PARI.

? ?bezout
bezout(x,y): gives a 3-dimensional row vector [u,v,d] such that 
             d=gcd(x,y) and u*x+v*y=d.
? bezout(130,61)
%1 = [23, -49, 1]


next up previous
Next: To solve Up: How to Solve Previous: How to Solve
William A Stein 2001-09-25