How does modulo work with negative numbers?
The modulo operator returns the remainder of a division. Doing an integer division and then multiplying it again means finding the biggest number smaller than a that is dividable by n without a remainder. Subtracting this from a yields the remainder of the division and by that the modulo.Similarly, ...