Specific content see purple book p313-p314
One, extended Euclidean algorithm
Idea: Find a pair of integers (x, y) so that ax+by=gcd (a, B)
For example: When "a=6,b=15", gcd (6,15) = 3, so you can get the solution "X=3,y=-1", of course, there are other solutions "X=-2,y=1".
Program:
/* Expand Euclidean algorithm */void gcd (int a, int b, int& D, int& x, int& y) {if (b = = 0) {//boundary, because a = gcd (a,0) = ax + 0y, so x=1 , y=0 d = a;x = 1;y = 0;} ELSE{GCD (b, a%b, D, y, X),//x and y order changed y-= x* (A/b);}}
The a,b,c in the equation below is any integer.
Conclusion 1: If the equation ax+by=c a set of integer solutions to (X0,Y0), then its arbitrary integer solution can be written (X0+KB ', Y0-ka '), where a ' = A/GCD (A, A, a), B ' = B/GCD (A, a), K takes any integer.
Conclusion 2: Set G = gcd (A, b), the equation ax+by=g a set of solutions is (X0,Y0), when C is a multiple of G ax+by=c a set of solutions is (x0c/g,y0c/g), when C is not a multiple of G no integer solution.
A preliminary study of number theory--Expanding Euclidean algorithm