Can $a \pmod b$ be negative for any integral value of $a$ and $b$?

43 Views Asked by At

Given $a$ and $b$ are integers, can there exist a negative value for $a \pmod b$?

1

There are 1 best solutions below

2
On

The Euclidian division theorem says that for any two integers $a,b\in \mathbb{Z}$ and $b\neq 0$, there exist unique integers $r,q\in\mathbb{Z}$ such that $a=bq+r$ and $0\leq r< |b|$. So if what you mean by $a\%b$ is calculating the residue of the division of $a$ and $b$, no, $r$ can not be negative.

If you meant that $a\% b$ is calculating $a$ mod$(b)$, then it can be negative, because the class of equivalence of $a$ in $\mathbb{Z}/b\mathbb{Z}$, $$[a]=\{\dots,a-2b,a-b,a,a+b,a+2b,\dots\}.$$