Algorithm: Understanding "extended Euclidean algorithm"

This algorithm is still a little meaning, requires some amount of thinking and understanding.

How to understand?

Before not extended Euclidean algorithm, calculating the greatest common divisor of two numbers, such as calculating the greatest common divisor of 144 and 24, the calculation process is as follows:
the beginning: 144 24
First: 24 144% 24 240 i.e.
found a direct integer, described divisor 24 is 144 , so the calculation result is: 24
if a, b is represented, it becomes a general form:
given two numbers (a, b), both now want to calculate the greatest common divisor, then the mold can then be b a, if the result is 0, it means that both the greatest common divisor b , if more than a few, for example:
the beginning: 146
for the first time: i.e. 6 6 6 2 14%
second: 26% 2 2 0 i.e.
Conversely: 2 is the greatest common divisor of 2, 6, 6, 14 and 6 is not the greatest common divisor, but K * 6 + 2 can be 14, and 6 can be divisible by 2, Note 2 is a divisor of 14.

After expansion

If the Euclidean algorithm is extended like this, for example:
14 424, we know that both the greatest common divisor is 24, then 144x + 24y = 24, the x, y, respectively, what is it? Obviously x = 0, y = 1; but if it is 14x + 6y = 2 it? By the above procedure, greatest common divisor, we can know, the last step of 2x1 + 6y1 = 2 is very easy to get results, but how about pushing back from this result, y start it? - This is the Extended Euclidean Algorithm.

Thus to understand:
14x + 6Y
6x2 + (14% 6) Y2
2X1 + (2% 6) Y1
step by step pushed forward, 6 14% 2 == described y2 = x1, then the 6x2 == (6% 2) y1 == (6 - 6/2 * 2) y1 ( here is divisible, with 7% 4 view is clearer, i.e. equal to 7 - 7/4 * 4)
by such a recursive, i.e., from the rear to pushed forward (or use a recursive thinking, has been returned to the bottom, and then calculate back) will be able to achieve this the algorithm.

Guess you like

Origin www.cnblogs.com/ZealYoung/p/11184223.html