From Link: enumz
1) solving a modal linear equation ax = b (mod n)
Equation ax = b (mod n), ax = b + NY->ax-ny = b
-AX + N (-y) =b where a,n,b is known. A set of special solutions to this equation can be obtained by expanding Euclidean.
Here are some theorems for solving the equation:
1. When and only when d|b, the equation ax = b (mod n) has a solution. D=GCD (A,n)
2.ax = b (mod n) either has a different solution of D, or no solution.
3. Make D=GCD (a,n) assume to Integer x ', y ', have d = Ax ' + NY ', if D | b, then the equation ax = b (mod n) has a solution with a value of x0, which satisfies:
X0=x ' (b/d) (mod n)
4. Assuming that the equation ax = b (mod n) has a solution, x0 is any solution to the equation, then the equation has a D different solution to modulo n, respectively:
Xi = x0 + i * (n/d), where i = 1,2,3......d-1
According to these 4 theorems, all solutions of the model linear equation can be easily obtained by using the extended Euclidean algorithm.
The pseudo code is as follows:
Modular_linear_equation_solver (a,b,n) (d,x ', y ') =extended_euclid (a,n) if (d|b) x0=x ' (b/d) mod n for i=0 to D-1 Print (X0+i (n/d)) mod nelse print "No Solutions"
2) solving the modular linear equation set
x = A1 (mod m1)
x = a2 (mod m2)
x = a3 (mod m3)
The first two equations of the equation group are solved. X=m1*k1+a1=m2*k2+a2
m1*k1+m2* (-K2) =a2-a1
This equation can be solved by Euclid to solve the k1 of the smallest positive integer x=m1*k1+a1 obviously x is the smallest positive integer solution of two equations.
The general solution of these two equations is X=X+K*LCM (m1,m2), x=x (mod LCM (m1,m2)), which transforms into a form of the same equation.
It is solved by this equation and the other equations behind it. The final result came out.
Solving the equations of linear equation by the algorithm