Modular arithmetic: Solving equation modulo prime number

328 Views Asked by At

I have an equation $$x \cdot a \equiv b\pmod m$$ where $a$ and $b$ are known and $m$ is a prime number.

I want to solve for $x$. If $b=1$ then $x=a^{m-2}$ but I need to solve it for any value of $b$.

I found this answer which seems to work but is there an easier way if $m$ is prime ?

1

There are 1 best solutions below

0
On BEST ANSWER

The integers mod. $m$ are a field if $m$ is prime. So, as in any other field, multiply both sides by $a^{-1}$:

$$x\equiv b a^{-1}\equiv ba^{m-2}\pmod m. $$ Note $a$ may very well have an order $< m-1 $. The only general result is that it is a divisor of $m-1$, and in real calculations, it may be useful to check its value.