# Generalizing the calculation of the module of negative numbers

I am trying to convince myself without using the calculator to compute the negative numbers that are moded by a positive number, i.e. ($-x \mod y$). I found out that if ($x<y$), then it is easy just by taking the difference between x and y: Example: $-10 \mod 17 = 17-10 = 7$.

However, I get stuck when $x>y$, For example, $-18 \mod 17 = 16$ so I really do not know how 16 comes up. Can someone explain how 16 is the answer? Or can you generalized the case ($x<y$)?

Thank you very much

• In the particular case when $x < y$ you just add $y$ to $-x$. But the general idea does not require $x$ to be less than $y$. You can just add $2y,3y,4y...$ to $x$ (until it is not negative anymore) and they will all share the same equivalence class. In your example, if you add $34=2\cdot 17$ to $-18$ you get $16$ which is what you want. Dec 10, 2016 at 18:33
• Keep adding $17$ till you reach a nonegative integer (just like you keep subtracting $17$ when the initial value is $\ge 17)\ \$ Dec 10, 2016 at 18:43

$c \equiv a \pmod b \equiv a\pm kb \pmod b$
When $a=-10 \Rightarrow 7 \equiv -10 \pmod{17} \equiv -27 \pmod{17} \equiv 24 \pmod{17}$
When $a=-18 \Rightarrow 16 \equiv -18 \pmod{17} \equiv -35 \pmod{17} \equiv -1 \pmod{17}$