1,
definition : Linear indeterminate equation refers to ax + by = c.
2,
The integers a, B, C are given, first a set of solutions is obtained, and then
Then discuss how to represent the general solution (all solutions). First set gcd (A; b) = d. If c is not a multiple of D, then the equation
No solution, because the left is a multiple of D, and the right is not. In the case of a solution, set c = C0£d, you can first ask
Out of ax + by = d for a group (x0; y0), then ax0 + by0 = d, both sides multiplied by C0: A (c0x0) + b (c0y0) = C, because
This (c0x0; c0y0) is a set of solutions to the original equation. In other words, the core problem is: ask for the solution of ax + by = gcd (A; b).
3,
The following extended Euclid algorithm is used to find such a set of solutions.
void gcd (intint int int. int int & y) {if 10;} Else { gcd (b, a// (*) y-= x* (A/b); }}
4, proof :
The mathematical induction method can prove its correctness. Inductive basis:
b = 0 o'clock, gcd (A; 0) = A, take x = 1; y = 0, with ax + by = a¢1 + 0¢0 = a = gcd (A; 0), established.
First, assuming I iterate, the line gets the correct result, that is, the return value y0 and x0 satisfy:
By0 + (a mod b) x0 = gcd (b; a mod b) = gcd (A; b) = d
After step y¡= x0¤ (a=b), the new number pair (x; y) satisfies:
Ax + by = ax0 + B (y0¡x0 (a=b)) = ax0 + by0¡bx0 (a=b) = s
The a=b here is the integer divide operation, which equals (a¡a mod b) =b,
so s = ax0 +by0¡bx0 (a¡a mod b) =b = ax0 +by0¡ax0 + (a mod b) x0 = By0 + (a mod b) x0 = d
Solving linear indefinite equations