# Thread: a mod b (remainder) with negative integers?

1. ## a mod b (remainder) with negative integers?

I understand how do calculate something like 25 mod 20, i.e. 25 mod 20 = 5. However, negatives confuse me. Such as 123 mod -123 or -89 mod -98. Can you offer some insight in dealing with negatives in the a mod b operation?

Thank you.

2. ## My answer

Originally Posted by mjlaz
I understand how do calculate something like 25 mod 20, i.e. 25 mod 20 = 5. However, negatives confuse me. Such as 123 mod -123 or -89 mod -98. Can you offer some insight in dealing with negatives in the a mod b operation?

Thank you.
a mod b can be done with any integer positive or negative it doesn`t matter .
a mod b gives you the remainder .
a mod b = (a - P*b) (P is quotient)

for instance take 123 mod -123
a = 123;b = -123 ;P = -1 so answer is 0 .