In a programming algorithm, I'm using the result of k % y
. I need to understand how to adjust k when the value of y is incremented by one to preserve the same modulo result.
In other words, solve for x:
(k + x) % (y + 1) = k % y
Empirically, I see that I can always adjust k by adding a constant that depends on both the value of k and the value of y.
I believe the solution involves computing some sort of "distance across y" between k % y
and k % (y + 1)
.
Hoping this is easy for someone who studied mathematics, rather than comp sci, as I'm out of my league here. Thanks!