60. Quotient and remainder

Let $m$ and $n$ be positive integers with $n\neq 0$. If you divide $n$ into $m$ you get a quotient and a remainder; for example, if you divide 4 into 14 you get a quotient 3 and a remainder 2. We will write the quotient when $m$ is divided by $n$ as $m \operatorname{div} n$ and the remainder as $m \bmod n$, so that $14 \operatorname{div} 4 = 3$ and $14 \bmod 4 = 2$. The basis for the formal definition given below is the property that $14 = 3\times 4 + 2$.

The following formal definition allows $m$ and $n$ to be negative as well as positive. This has surprising consequences discussed in Section 61.3.

60.1 Definition: quotient and remainder

Let $m$ and $n$ be integers. Then $q = m \operatorname{div} n$ and $r = m \bmod n$ if and only if $q$ and $r$ are integers that satisfy both the following equations:

Q.1 $m = qn + r$, and

Q.2 $0\leq r < |n|$.

If $q = m \operatorname{div} n$, then $q$ is the quotient (of integers) when $m$ is divided by $n$. If $r = m \bmod n$, then $r$ is the remainder when $m$ is divided by $n$.

60.1.1 Remarks

a) It follows from the definition that the equation

$$m = (m \operatorname{div} n)n + (m \bmod n) \tag{60.1}$$

is always true for $n\neq 0$.

b) On the other hand, if $n = 0$, Q.2 cannot be true no matter what $r$ is. In other words, “$m \operatorname{div} 0$” and “$m \bmod 0$” are not defined for any integer $m$.

60.1.2 Exercise Find the quotient (of integers) and remainder when $m$ is divided by $n$:

a) $m = 2$, $n = 4$.

b) $m = 0$, $n = 4$.

c) $m = 24$, $n = 12$.

d) $m = 37$, $n = 12$.

(Answer on page 245.)

60.1.3 Warning For $q$ to be $m \operatorname{div} n$ and $r$ to be $m \bmod n$, both Q.1 and Q.2 must be true. For example, $14 = 2\times 4 + 6$ (so Q.1 is satisfied with $q = 2$ and $r = 6$), but $14 \bmod 4\neq 6$ because Q.2 is not satisfied.

60.1.4 Exercise Suppose that $a$ and $b$ leave the same remainder when divided by $m$. Show that $a-b$ is divisible by $m$. (Answer on page 245.)

60.1.5 Exercise Suppose that $a-b$ is divisible by $m$. Show that $a$ and $b$ leave the same remainder when divided by $m$.

60.1.6 Exercise Suppose that $a \operatorname{div} m = b \operatorname{div} m$. Show that $|a-b| < |m|$.

60.1.7 Exercise Is the converse of Exercise 60.1.6 true? That is, if $|a-b| < |m|$, must it be true that $a \bmod m = b \bmod m$?

The following theorem is what mathematicians call an “existence and uniqueness” theorem for quotient and remainder.

60.2 Theorem: Existence and Uniqueness Theorem for quotient and remainder

For given integers $m$ and $n$ with $n \neq 0$, there is exactly one pair of integers $q$ and $r$ satisfying the requirements of Definition 60.1.

60.2.1 Remark This theorem says that when $n \neq 0$ there is a quotient and a remainder, i.e., there is a pair of numbers $q$ and $r$ satisfying Q.1 and Q.2, and that there is is only one such pair.

60.2.2 Worked Exercise Suppose that $m = 3n + 5$ and $n > 7$. What is $m \operatorname{div} n$? Answer $m \operatorname{div} n = 3$. The fact that $m = 3n + 5$ and $n > 7$ (hence $n > 5$) means that $q = 3$ and $r = 5$ satisfy the requirements of Definition 60.1.

60.2.3 Exercise Suppose $a$, $b$, $m$ and $n$ are integers with $m$ and $n$ nonnegative such that $m = (a + 1)n + b + 2$ and $m \operatorname{div} n = a$. Show that $b$ is negative. (Answer on page 245.)

60.2.4 Exercise Suppose $n > 0$, $0\leq s < n$ and $n \mid s$. Show that $s = 0$. (Answer on page 246.)

There is a connection between these ideas and the idea of “divides” from Definition 4.1 (page 4):

60.3 Theorem

If $n \neq 0$ and $m \bmod n = 0$, then $n \mid m$.

Proof If $m \bmod n = 0$, then by Q.1, $m = (m \operatorname{div} n)n$, so by Definition 4.1 (using $m \operatorname{div} n$ for $q$), $n$ divides $m$.

60.4 Mod and div in Mathematica

To compute $m \operatorname{div} n$ in Mathematica, you type Quotient[m,n], and to compute $m \bmod n$, you type Mod[m,n]. You can if you wish place either of these function names between the inputs surrounded with tildes: m ~Quotient~ n is the same as Quotient[m,n], and m ~Mod~ n is the same as Mod[m,n].

60.5 Proof of uniqueness

We will prove that the quotient and remainder exist in Section 104.3.2, page 156. It is worthwhile to see the proof that the quotient and remainder are unique, since it shows how it is forced by Definition 60.1.

Suppose $m = qn + r = q'n + r'$ and both pairs $\langle q,r\rangle$ and $\langle q',r'\rangle$ satisfy Q.2. We must show that the two ordered pairs are the same, that is, that $q = q'$ and $r = r'$.

By Q.2 we have $0\leq r < |n|$ and $0\leq r' < |n|$. Since $r$ and $r'$ are between 0 and $|n|$ on the number line, the distance between them, which is $|r-r'|$, must also be less than $n$. A little algebra shows that

$$|r - r'| = |q' - q|\,|n|$$

It then follows from Definition 4.1, page 4, that $|r - r'|$ is divisible by $|n|$. But a nonnegative integer less than $|n|$ which is divisible by $|n|$ must be 0 (Exercise 60.2.4). So $r = r'$. Since $qn + r = q'n + r'$, it must be that $q = q'$, too. So there can be only one pair of numbers $q$ and $r$ satisfying Q.1 and Q.2.

This proof uses the following method.

60.5.1 Method

To prove that an object that satisfies a certain condition is unique, assume there are two objects $A$ and $A'$ that satisfy the condition and show that $A = A'$.

60.5.2 Exercise Use Definition 60.1 and Theorem 60.2 to prove that when 37 is divided by 5, the quotient is 7 and the remainder is 2. (Answer on page 246.)

60.5.3 Exercise Use Definition 60.1 and Theorem 60.2 to prove that $115 \operatorname{div} 37 = 3$.

60.5.4 Exercise Suppose that $m = 36q + 40$. What is $m \bmod 36$? (Answer on page 246.)

60.5.5 Exercise Prove that if $q$, $m$ and $n$ are integers and $0\leq m-qn < |n|$, then $q = m \operatorname{div} n$.

60.5.6 Exercise Show that if $a$ and $b$ are positive integers and $a \bmod 4 = b \bmod 4 = 3$, then $ab \bmod 4 = 1$.

60.5.7 Exercise Prove that for any integer $c$, $c^{2} \bmod 3$ is either 0 or 1.

60.6 More about definitions

Observe that Definition 60.1 defines “$m \operatorname{div} n$” and “$m \bmod n$” without telling you how to compute them. Normally, you would calculate them using long division, but the uniqueness Theorem 60.2 tells you that if you can find them some other way you know you have the right ones. A mathematician would say that Theorem 60.2 ensures that the quotient (of integers) $m \operatorname{div} n$ and the remainder $m \bmod n$ are well-defined, or that Definition 60.1 and Theorem 60.2 work together to characterize the quotient and remainder.

It is typical of definitions in abstract mathematics that they characterize a concept without telling you how to compute it. The technique of separating the two ideas, “what is it?” and “how do you compute it?”, is fundamental in mathematics.

Pages 82–85 of the book (PDF).