IDA: Interactive Document on Algebra

We are ready for the general case.

Algorithm

  • Input: integers a, b, c, with a and b not both 0.
  • Output: all integer solutions x, y to the equation xa + yb = c.

  1. Find, using the extended Euclidean algorithm, integers x', y' such that d := gcd(a,b) = x'a + y'b.
  2. If d does not divide c, then return that there are no solutions to the equation.
  3. If d | c, then return

    x = (x'c - nb)/d   and   y = (y'c + na)/d     (n Z).

Note the structure of the solutions: x'c/d, y'c/d is one particular solution of the equation xa + yb = c, and all other solutions are obtained by adding all solutions of the homogeneous equation xa + yb = 0 to it.