Preface
For many number theory problems, it is necessary to involve GCD, solve gcd, and often use Euclidean algorithm.
For many solving problems, the Bézout equation can be listed: AX+BY=GCD (A, B), with the EXGCD solution to the answer, EXGCD is the expansion of Euclid algorithm.
Here's a little learning about the two algorithms
Content
Euclidean algorithm
by Baidu Encyclopedia
Euclidean algorithm, also known as the greatest common divisor method, is used to calculate two positive integers, a, B.
From the division of integers can be seen: for any given two integers a,b0, there must be two integers q and R exist, make A=QB+R,0≤RB, and Q and R is the only existence, this is a fundamental theorem of number theory, a series of important properties of integers are derived from this, if repeated use of this fundamental theorem, can be obtained because each time division, the remainder is at least one, and B is a finite number of positive integers, so at most b times, you can always get a remainder is a zero equation, that is, rn+1=0.
Of course, Baidu said this kind of words I can not understand.
In fact, the GCD (A, B) =gcd (b,a MoD), until a≡0 (mod b) , B is the request.
The purpose of this method is to achieve a reduction in the number of two numbers that can be solved, making the efficiency a logarithmic level.
So, how do we prove the correctness of this formula?
We make
Depending on the definition of the modulo operation, there can be
GCD&EXGCD algorithm