now I have one formula:
int a = 53, x = 53, length = 62, result;
result = (a + x) % length;
but how to calculate reverse modulus to get the smallest "x" if I known result already
(53 + x) % 62 = 44
//how to get x
i mean what's the formula or logic to get x
e.g. :
how about
I'm now aware this answer is flawed because it does not gice the smallest but a
.First()
would fix that.Who needs a computer? If 53 + x is congruent to 44, modulo 62, then we know that for integer k,
Solving for x, we see that
Clearly the smallest solutions are -9 (when k=0) and 53 (when k=1).
It may not be the X that was originally used in the modulus, but if you have
(A + x) % B = C
You can do
(B + C - A) % B = x
x = (44 - 53) % 62
should work?