So about the Extended Euclidean algorithm, the algorithm that finds, a
, b
, and d
in the equation am+bn=d
, where m
and n
are two positive integers, d
is their GCD, and a
and b
are two integers (not necessarily positive)
So the book I am following has the following instructions for implementing this algorithm:
E1. [Initialize.] Set a′ ← b ← 1, a ← b′ ← 0, c ← m, d ← n.
E2. [Divide.] Let q and r be the quotient and remainder, respectively,
of c divided by d. (We have c = qd + r and 0 ≤ r < d.)
E3. [Remainder zero?] If r = 0, the algorithm terminates;
we have in this case am + bn = d as desired.
E4. [Recycle.] Set c ← d, d ← r, t ← a′, a′ ← a, a ← t − qa, t ← b′, b′ ← b, b ← t − qb,
and go back to E2.
My problem is that I don't particularly understand all the math around this algorithm, I understand the normal Euclidean algorithm well enough, so I understand half of the extended one as well. What I don't understand is the need for a'
and b'
as well t
(I get that t
is a temporary variable but I don't get the a = t - qa
and b = t - qb
part). That as well as the initialization of the variables a
, a'
, b
, and b'
as well as the swapping of the values between them on each iteration. Can anybody help me bridge these gaps in my understanding of this algorithm?