Euclidean algorithm: Also known as the Euclidean method
GCD (A, B) =gcd (B,A%B);
termination conditions A=GCD b=0;
(GCD is a, B greatest common divisor)
Extended Euclidean algorithm: A and B greatest common divisor is gcd, must be able to find such x and Y, making: a*x + b*y = GCD established
We only need to find special solution x0,y0;
The general solution is X = x0 + (B/GCD) *t y = y0– (A/GCD) *t
So how do we find the next set of solutions?
Modeled after Euclid algorithm a=b,b=a%b.
A%b = A-(A/b) *b (Here the "/" refers to the divide) can be obtained:
GCD = B*x1 + (A-(A/b) *b) *y1
= b*x1 + a*y1– (A/b) *b*y1
= A*y1 + b* (x1–a/b*y1)
Compare easily to x = y1
y = x1–a/b*y1
a*1 + b*0 = gcd is a coefficient of 1,b with a factor of 0 or other value (*0=0)
We'll see the river again. A=s,b=s+1,ax+by=n A, B, greatest common divisor is 1 because it is an adjacent natural number
The ax+by=n is obtained by the Ax+by=1 (1 for greatest common divisor) de coefficient *n.
Not to be continued.
Euclidean algorithm and extended Euclidean algorithm (the second problem of the river noip2005 raising group)