If I have an equation like (x+c) mod y = z and I need to solve for y, how would I go about doing that?
Apologies if this is more math than programming.
If I have an equation like (x+c) mod y = z and I need to solve for y, how would I go about doing that?
Apologies if this is more math than programming.
No simple formula exists. If a mod n = r
then n
divides a-r
and 0 <= r < n
. Candidate n
can be found by factoring a - r
and finding divisors which are larger than r
. Factoring is a much-studied but non-trivial problem. Pick your favorite factoring algorithm. Unless a-r
is prime, there won't be a unique solution (unless r
is larger than any proper-divisor of a-r
).