1
$\begingroup$

I'm trying to figure out how the modulo operation works using long division with negative dividends.

I know that $-1 \bmod 10 = 9$. But I can't figure out why.

For positive dividends, it's relatively straightforward.

$1 \bmod 10$ is the remainder of the long division of $1 ÷ 10$, which is $1$.

long division of 1 /÷10

But when I try to find the remainder of the long division of $-1 ÷ 10$, I get $-1$, not $9$.

long division of -1 /÷10

What am I doing wrong or failing to grasp?

$\endgroup$
2
$\begingroup$

When we divide $a$ by $b$ we can write $a=qb+r$ where $q$ is the quotient and $r$ is the remainder. We usually define $r \in [0,b-1]$ and it looks like you are doing so. In that case we write $-1=-1\cdot 10+9$, so the quotient is $-1$ and the remainder is $9$. You want the largest multiple of $b$ that is less than $a$. In your example that is $-10$, not $0$ as $0 \not \lt -1$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.