ModularLinearEquationSolver(a, b, n) ; O(lgn + gcd(a,n)) (d, x', y') = Extended-Euclid(a, n) ; arithmetic operations if (d b) then x0 = x'(b/d) mod n for i = 0 to d-1 print (x0 + i(n/d)) mod n else print ``no solutions''
Note: Solving ax 1 (mod n) gives mod n (only one solution).