How to solve equations with modulus in them

80 Views Asked by At

For e.g.

(100 * X) % 35 = 25

gives X = 2

and on similar note

(100 * X) % 360 = 80

gives X = 8

and it can be possible that there is no X which satisfy this

for e.g.

(100 * X) % 360 = 70

there is no X possible in above case

1

There are 1 best solutions below

0
On

Using C notation (a*X) % n = b, such a $X$ exists if and only if the GCD (greatest common divisor) of $a$ and $n$ is a divisor of $b$ (of course, assuming $0 \le b < n$). I am afraid that the method to actually find a solution uses more tools than you are familiar with, but at least you can easily check whether a solution exists, and if so you can always do an exhaustive search, which should be fine in your setting. (If you want to know more, a Google search for "linear congruence" yields plenty of references, but you might have to get familiar with congruences first.)