1

How do you calculate the remainder for a division like: $$ (-a) \mod b,\; \mbox{ where } a<b? $$ For example, for $-7 \mod 26$, what will be the quotient and the remainder?

Mee Seong Im
  • 3,190
  • 1
  • 15
  • 22
k1gabi
  • 13
  • 1
    Typically, one requires the remainder to be one of ${0,\cdots, b-1}$. Thus, in your example, we would like to write $-7=26q+r$ for $r\in {0,\cdots, 25}$. Easy to see that $q=-1,r=19$ works. – lulu Jun 11 '17 at 13:16

2 Answers2

1

The most common definition is that remainder is equal to

$b-a$ for $a<b$
from the equation $a=quotient*b+remainder $ we see that the $quotient$ is always $-1$.

Remainder is

$b-(a$ $mod$ $b)$ for $a>b$ from the same equation we get $quotient=\frac{a-b+ (a\mod b)}{b}$.

See for example this article from London University.

TGar
  • 175
1

First of all, we need a precise definition of division with remainder.

Definition. Let $a$ and $b$ integers, $b\neq 0$. If there exist integers $q$ and $r$ such that $$a=bq + r,\ 0\leq r <|b|$$ we call $q$ quotient and $r$ remainder.

Theorem. Let $a$ and $b$ integers, $b\neq 0$. There exist unique integers $q$ and $r$ such that $$a=bq + r,\ 0\leq r <|b|.$$

To prove the existence in the above theorem, first you could consider only positive $a$ and $b$ and define $$q := \min\{ n\mid bn > a\}-1.$$ From the definition we have $$bq \leq a < b(q+1)\implies 0\leq a-bq <b$$ so define $$r:= a -bq.$$

For negative $a$ or $b$ one could do a bit of casework to get things done.

For the uniqueness part, assume $bq + r = bq' + r'$. Then we have $b(q-q') = r' - r$ and $r'-r$ is divisible by $b$. But, $0\leq r<|b|$ and $0\leq r'<|b|$ implies that $-|b|<r'-r<|b|$ and thus $r'-r = 0$. It immediately follows that $q = q'$ as well.

Thus, when we have $a= -7$ and $b=26$ we need to find $r$ and $q$ such that $$-7 = 26q + r,\ 0\leq r < 26, $$ or equivalently an integer $q$ such that $0\leq -7-26q<26$. You can easily see that $q= -1$ works and that the remainder is $r = 19$.

Ennar
  • 23,082