Platinum Partner

Modular Linear Equation Solver

Prints the roots of this equation:
ax = b (mod n)

Relies on Euclid's extended algorithm:
http://snippets.dzone.com/posts/show/4192


def solveLinearModularEquation(a, b, n):
  d, xx, yy = euclidExtended(a, n)
  if (b % d == 0):
    x0 = (xx * (b / d)) % n
    for i in xrange(0, d):
      print (x0 + i * (n / d)) % n,
  else:
    print "No solution"
  print
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}