For ax + by = gcd (a, b)
Such equations can be used to obtain a exgcd Extended Euclidean Algorithm for General Solution.
Seeking Euclidean GCD: GCD (A, B) = GCD (B, A% B)
Available bx + (a% b) y = gcd (b, a% b)
Ne据
a% b = a- (a / b) * b
Yes obtained bx + ay- (a / b) b * y = gcd (b, a% b)
Simplification have ay + b (x- (a / b) y) = gcd (b, a% b)
x ' = and , and ' = ( x - ( a / b ) and )
ax′+by′=gcd(b,a%b)<=>ax+by=gcd(a,b)
according to
gcd(a,0)=a
B been recursively until 0 is available
ax + by = a
Can derive a set of trivial solution x = 1, y = 0
It has a set of recursion can be drawn trivial solution, then with Zaiwang Hui ax by a set of solutions + = gcd (a, b) (the obtained X ' = Y , Y ' = ( X - ( A / B ) the y- ) )
Generalization view indeterminate equation
ax + by = c
Only meet c% gcd (a, b) == 0 only solution.
Congruence equation solving Fermat's Little Theorem can also be used to seek to expand Euclid seek
ax≡b mod n <==> ax + ny = b
It is transformed into the above form
Fermat's Little Theorem: a prime number is a positive integer divisible by p on can be, there are a ^ (p-1) ≡ 1 (mod p)
Derivation: a ^ (p-1) = 1 (mod) p = a * a ^ (p-2) ≡1 (mod p) is the inverse element of a thus a ^ (p-2); so to satisfy Fermat little Theorem can be directly used to quickly seek power