Recursive Version
Non-recursive Version
Calculation by Hand
For example, calculate exgcd(108,68)
a (ri) | b | xi=xi−2−xi−1qi−1 | yi=yi−2−yi−1qi−1 | |
---|
0 | 108 | 1 | 0 | |
108 | 68 | 0 | 1 | |
68 | 40 | 1 | -1 | |
40 | 28 | -1 | 2 | |
28 | 12 | 2 | -3 | |
12 | 4 | -5 | 8 | |
4 | 0 | | | |
this gives | | | | |
−5×108+8×68=gcd(108,8)=4