Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have three known numbers : $a$, $b$ and $m$.

I want to find the smallest $x$ so that $a.x \equiv b\ (mod\ m)$ (the product of $a$ and $b$ is congruent to $b$ modulo $m$).

In the cases where such an $x$ exists, is there a simple equation that allows me to get the value for $x$ ?

Note: the numbers $a$, $b$ and $m$ can be very large numbers. I am looking for a direct resolution of the equation, not a solution involving iterating through all possible values of $x$ or modular-rewriting of $a$ and $b$.

share|cite|improve this question
There is no simple equation, but there is a simple and efficient algorithm, Euclid's. You'll probably find it explained in several earlier questions on this site. – Gerry Myerson Aug 24 '12 at 12:45
Thanks for that, Gerry ! – subtenante Aug 25 '12 at 10:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.