posted by Francesca on .
How do I solve for negative modular arithmetic?
Here is an example: -45 mod 13 = 7, but how?
a mod b = (a + nb) mod b
so, -45 mod 13 = mod (-45 + 52) mod 13 = 7 mod 13 = 7
Just add a big enough multiple of the modulus so you have a positive number.