Note: Due to the special nature of programming, the linear homogeneous equation of N element is rarely used in ACM. I learned it out of interest.
The concept of linear homogeneous equation of N element:
For example: (A1 * X1 + A2 * X2 + .... + an * XN) % m = B % m .................. (1)
Of course there are also many variants, such as A1 * X1 + A2 * X2 +... + an * xn + M * x (n + 1) = B. both are equivalent.
Determine whether there is a solution:
To solve a linear homogeneous equation, we must first determine whether the equation has a solution. The Sufficient Condition for the equation to have a solution is: d % B = 0. where d = gcd (A1, A2 ,... an );
To solve the linear homogeneous equation of N yuan, we convert it into an Indefinite Equation of N yuan.
A1 * X1 + A2 * X2 +... + an * xn + M * x (n + 1) = B ................... (2)
It is not hard to prove that (2) and (1) are completely equivalent. The specific proof is also very simple, so we will not prove it here.
(2) The required and sufficient conditions for the solution are: d1 % B = 0. D1 = gcd (A1, A2,... an, m ).
Theorem: when (1) has a solution, there are D1 * m ^ (n-1) different solutions.
Theorem: when (1)
Equation solving:
Set d1 = gcd (A1, A2,... an, m), and D1 % B = 0.
Take advantage of the same remainder type:
Solution to number theory-N element Linear coordinalequations