Skip to main content \(\newcommand{\longdivision}[2]{#1\big)\!\!\overline{\;#2}}
\newcommand{\mlongdivision}[2]{\longdivision{#1}{#2}}
\renewcommand{\emptyset}{\{\}}
\newcommand{\blanksp}{\underline{\hspace{.25in}}}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\cspace}{-}
\newcommand{\Ta}{\mathtt{a}}
\newcommand{\Tb}{\mathtt{b}}
\newcommand{\Tc}{\mathtt{c}}
\newcommand{\Td}{\mathtt{d}}
\newcommand{\Te}{\mathtt{e}}
\newcommand{\Tf}{\mathtt{f}}
\newcommand{\Tg}{\mathtt{g}}
\newcommand{\Th}{\mathtt{h}}
\newcommand{\Ti}{\mathtt{i}}
\newcommand{\Tj}{\mathtt{j}}
\newcommand{\Tk}{\mathtt{k}}
\newcommand{\Tl}{\mathtt{l}}
\newcommand{\Tm}{\mathtt{m}}
\newcommand{\Tn}{\mathtt{n}}
\newcommand{\To}{\mathtt{o}}
\newcommand{\Tp}{\mathtt{p}}
\newcommand{\Tq}{\mathtt{q}}
\newcommand{\Tr}{\mathtt{r}}
\newcommand{\Ts}{\mathtt{s}}
\newcommand{\Tt}{\mathtt{t}}
\newcommand{\Tu}{\mathtt{u}}
\newcommand{\Tv}{\mathtt{v}}
\newcommand{\Tw}{\mathtt{w}}
\newcommand{\Tx}{\mathtt{x}}
\newcommand{\Ty}{\mathtt{y}}
\newcommand{\Tz}{\mathtt{z}}
\newcommand{\So}{\Tf}
\newcommand{\Sno}{\Tg}
\newcommand{\Si}{\Th}
\newcommand{\Sni}{\Tj}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\W}{\mathbb{W}}
\newcommand{\ZZ}{\Z}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\RR}{\R}
\newcommand{\F}{\mathbb{F}}
\newcommand{\A}{\mathbb{A}}
\newcommand{\abs}[1]{|#1|}
\newcommand{\fmod}{\bmod}
\newcommand{\fdiv}{\,\mathrm{div}\,}
\newcommand{\lcm}{\mathrm{lcm}}
\newcommand{\id}{\mathrm{id}}
\newcommand{\nr}[1]{\##1}
\newcommand{\gexp}[3]{#1^{#2 #3}}
\newcommand{\gexpp}[3]{\displaystyle\left(#1\right)^{#2 #3}}
\newcommand{\glog}[3]{\log_{#1}^{#3}#2}
\newcommand{\sol}[1]{{\color{blue}\textit{#1}}}
\newcommand{\gro}[1]{{\color{gray}#1}}
\newcommand{\todo}[1]{{\color{purple}TO DO: #1}}
\newcommand{\fixme}[1]{{\color{red}FIX ME: #1}}
\newcommand{\checkme}[1]{{\color{green}CHECK ME: #1}}
\newcommand{\degre}{^\circ}
\newcommand{\vect}[1]{\overrightarrow{#1}}
\newcommand{\nix}{}
\newcommand{\cox}[1]{\fcolorbox[HTML]{000000}{#1}{\phantom{M}}}
\newcommand{\tox}[1]{\texttt{\##1} \amp \cox{#1}}
\newcommand{\ttx}[1]{\texttt{\##1}}
\newcommand{\mox}[1]{\mathtt{\##1}}
\newcommand{\xx}{\mathtt{\#}}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 3.4 The Operation \(mod\)
In this section we investigate the properties of the operation
\(\fmod\) and show how these can be applied. The properties will seem awkward at first but will turn out to be powerful tools in computations when numbers get larger. In the video in
Figure 3.29 we give an overview of the properties of
\(\fmod\) covered in this section.
Figure 3.29. The operation \(\fmod\) by Matt Farmer and Stephen Steward Before we get to the properties we recall how to compute
\(\fmod\) and make some observations about the behavior of
\(\fmod\text{.}\)
Subsection Computing \(\fmod\)
Recall that
\(a\fmod b\) is the remainder of the division of
\(a\) by
\(b\) (see
Definition 3.18 ). We have established that the division algorithm (
Algorithm 3.6 and
Algorithm 3.12 ) produces the quotient and remainder of a particular division as its output values. As an alternative method we have presented (calculator) long division in
Strategy 3.1 .
In the following examples we compute a remainder by inspection, with the division algorithm, and with (calculator long division).
Example 3.30 . Three methods for computing \(41\fmod 13\) .
We compute \(41\fmod 13\) in three different ways. The number \(41 \fmod 13\) is the remainder of the division of \(41\) by \(13\text{.}\)
Method 1 the trained eye. The largest multiple of 13 that is less than 41 is 39. The difference between 41 and 39 is 2, this is the remainder of the division of 41 by 13. Thus 41 mod 13 = 2.
Method 2 calculator long division. We have
\(41\div 13=3.153\dots\text{.}\) So the quotient from the decision of
\(41\) by
\(13\) is the largest integer that is less than
\(3.153\dots\text{,}\) which is
\(3\text{.}\) The remainder is
\(41-3\cdot 13 = 41-39 = 2\text{.}\) Thus
\(41 \mod 13 = 2\text{.}\)
Method 3 division algorithm.
We subtract \(13\) until we get a number in the remainder target range from \(0\) to \(13-1=12\text{:}\)
\begin{align*}
41-13\amp =28\\
28-13\amp =15\\
15-13\amp =2
\end{align*}
As \(2\) is in the remainder target range from \(0\) to \(13-1=12\) it is the remainder. Thus 41 mod 13 = 2.
Example 3.31 . Three methods for computing \(-41\fmod 13\) .
We compute \(-41\fmod 13\) in three different ways. The number \(-41 \fmod 13\) is the remainder of the division of \(-41\) by \(13\text{.}\)
Method 1 the trained eye. The smallest multiple of
\(13\) that is greater than
\(41\) is
\(52\text{.}\) The sum of
\(-41\) and
\(52\) is
\(11\text{,}\) this is the remainder of the division of
\(-41\) by
\(13\text{.}\) Thus
\(-41 \fmod 13 = 11\text{.}\)
Method 2 calculator long division. We have
\(-41\div 13=-3.153\dots\text{.}\) So the quotient of the division of
\(41\) by
\(13\) is the largest integer that is less than
\(-3.153\dots\) which is
\(-4\text{.}\) The remainder is
\(-41+4\cdot 13 = -41+52 = 11\text{.}\) Thus
\(-41 \fmod 13 = 11\text{.}\)
Method 3 division algorithm.
We add \(13\) until we get a number in the remainder target range from \(0\) to \(13-1=12\text{:}\)
\begin{align*}
-41+13\amp =-28\\
-28+13\amp =-15\\
-15+13\amp =-2\\
-2+13\amp =11
\end{align*}
As \(11\) is in the remainder target range from \(0\) to \(13-1=12\) it is the remainder. Thus -41 mod 13 = 11.
The three methods are also subject of the video in
Figure 3.32 .
Figure 3.32. How to compute \(\fmod\) by Frances Clerk
Subsection Some observations
An interesting pattern occurs when we compute the remainder of consecutive integers from the divisions by the same number. As illustrated in the following two examples, the remainders repeat in a periodic fashion.
Example 3.33 . Integers modulo three.
\begin{align*}
0\fmod 3\amp =0 \\
1\fmod 3\amp =1 \\
2\fmod 3\amp =2\\
3\fmod 3\amp =0 \\
4\fmod 3\amp =1 \\
5\fmod 3\amp =2\\
6\fmod 3\amp =0 \\
7\fmod 3\amp =1 \\
8\fmod 3\amp =2
\end{align*}
Example 3.34 . Integers modulo two.
\begin{align*}
0\fmod 2\amp =0 \\
1\fmod 2\amp =1 \\
2\fmod 2\amp =0\\
3\fmod 2\amp =1 \\
4\fmod 2\amp =0 \\
5\fmod 2\amp =1\\
6\fmod 2\amp =0 \\
7\fmod 2\amp =1 \\
8\fmod 2\amp =0
\end{align*}
The remainder of division by
\(2\) is an integer that is greater than or equal to
\(0\) and less than
\(2\text{,}\) that is, it is either
\(0\) or
\(1\text{.}\) We use this to define two familiar terms.
Definition 3.35 .
An integer
\(n\) is
even means that
\(n \fmod 2 = 0\text{.}\)
Definition 3.36 .
An integer
\(n\) is
odd means that
\(n \fmod 2 = 1\text{.}\)
Subsection Properties of \(\fmod\)
We now investigate some properties of the operation
\(\fmod\text{.}\) In particular, we are interested in the behavior of
\(\fmod\) in sums and products.
To get an idea how
\(\fmod\) behaves under addition we look at an example.
Example 3.37 . Addition and \(\fmod\) .
We have
\begin{equation*}
(11+5) \fmod 7 = 16 \fmod 7 = 2.
\end{equation*}
Let’s try we whether we can distribute \(\fmod\) over the addition.
\begin{equation*}
(11 \fmod 7) + (5\fmod 7) = 4 + 5 = 9.
\end{equation*}
We see that
\begin{equation*}
(11 \fmod 7) + (5\fmod 7) \ne (11+5) \fmod 7.
\end{equation*}
But we notice that \(9\fmod 7=2\text{.}\) So computing \(\fmod 7\) once more will yield equality:
\begin{equation*}
((11 \fmod 7) + (5\fmod 7))\fmod 7 = (4 + 5)\fmod 7 = 11 \fmod 7=2.
\end{equation*}
So, we have
\begin{equation*}
((11 \fmod 7) + (5\fmod 7))\fmod 7 = (11+5) \fmod 7.
\end{equation*}
We build upon our observations in the example to formulate a theorem about addition in combination with the operation
\(\fmod\text{.}\)
Theorem 3.38 .
Let \(a\) and \(b\) be integers, and let \(m\) be a natural number. Then
\begin{equation*}
(a+b)\fmod m=\bigl((a\fmod m)+(b\fmod m)\bigr)\fmod m
\end{equation*}
Proof.
We have that
\begin{align*}
a\amp =(a \fmod m)+(s\cdot m) \text{ for some integer } s, \text{ and }\\
b\amp =(b \fmod m)+(t\cdot m) \text{ for some integer } t\text{.}
\end{align*}
With the notation above, we have
\((a+b)\fmod m\) \(=\bigl(((a \fmod m)+(s\cdot m))+((b \fmod m)+(t\cdot m))\bigr)\fmod m\) \(=\bigl((a \fmod m)+(b \fmod m)+(s+t)\cdot m\bigr)\fmod m\) \(=\bigl((a \fmod m)+(b \fmod m)\bigr)\fmod m\)
Example 3.39 . Addition with and without Theorem 3.38.
We illustrate
Theorem 3.38 with an example. We compute
\((10+20)\fmod 7\) in two ways, namely directly and applying the theorem.
\(\displaystyle (10+20)\fmod 7 = 30 \fmod 7 = 2\)
\((10+20)\fmod 7\) \(= \left((10 \fmod 7)+(20 \fmod 7)\right) \fmod 7\) \(= (3+6)\fmod 7\) \(= 9\fmod 7 =2\)
Using the theorem may seem more awkward right now. When calculations get more involved its value will become more apparent. The theorem also can be used to evaluate expressions when we only know the remainders.
Problem 3.40 . Apply Theorem 3.38.
Let
\(a\) and
\(b\) be integers with
\(a\fmod 113=29\) and
\(b\fmod 113=100\text{.}\) Compute
\((a+b)\fmod 113\text{.}\)
Solution .
\begin{equation*}
(a+b)\fmod 113 = \left((a\fmod 113)+(b\fmod 113)\right) \fmod 113
\end{equation*}
As we know that
\(a\fmod 113=29\) and
\(b\fmod 113=100\) we can replace
\(a\fmod 113\) by
\(29\) and
\(b\fmod 113\) by
\(100\text{.}\) Copying what we have so far and evaluating we get:
\((a+b)\fmod 113\) \(=\left((a\fmod 113)+(b\fmod 113)\right) \fmod 113\) \(= (29+100)\fmod 113\) \(= 129 \fmod 113 = 16\)
Next we explore how multiplication and
\(\fmod\) interact.
Example 3.41 . Multiplication and \(\fmod\) .
We have
\begin{equation*}
(11\cdot 5) \fmod 7 = 55 \fmod 7 = 6.
\end{equation*}
Let’s try we whether we can distribute \(\fmod\) over the addition.
\begin{equation*}
(11 \fmod 7) \cdot (5\fmod 7) = 4 \cdot 5 = 20.
\end{equation*}
We see that
\begin{equation*}
(11 \fmod 7) \cdot (5\fmod 7) \ne (11\cdot 5) \fmod 7.
\end{equation*}
But we notice that \(20\fmod 7=6\text{.}\) So computing \(\fmod 7\) once more will yield equality:
\begin{equation*}
((11 \fmod 7) \cdot (5\fmod 7))\fmod 7 = (4 \cdot 5)\fmod 7 = 20 \fmod 7=3.
\end{equation*}
So, we have
\begin{equation*}
((11 \fmod 7) \cdot (5\fmod 7))\fmod 7 = (11\cdot 5) \fmod 7.
\end{equation*}
The observations made in the example suggests that a theorem analogous to
Theorem 3.38 holds for multiplication. Indeed we have:
Theorem 3.42 .
Let \(a\) and \(b\) be integers, and let \(m\) be a natural number. Then
\begin{equation*}
(a\cdot b)\fmod m=\bigl((a\fmod m)\cdot(b\fmod m)\bigr)\fmod m\text{.}
\end{equation*}
Proof.
There are integers \(s\) and \(t\) such that
\begin{equation*}
a =(a \fmod m)+(s\cdot m)
\end{equation*}
and
\begin{equation*}
b =(b \fmod m)+(t\cdot m).
\end{equation*}
Thus \((a\cdot b)\fmod m\) \(=\bigl(((a \fmod m)+s\cdot m)\cdot ((b \fmod m)+t\cdot m)\bigr)\fmod m\) \(= \bigl((a \fmod m)\cdot(b \fmod m)\) \(\qquad + (a \fmod m) \cdot t\cdot m + s\cdot m \cdot (b \fmod m) + s\cdot m \cdot t\cdot m \bigr) \fmod m\) \(=\bigl((a \fmod m)\cdot(b \fmod m)\) \(\qquad +\bigl((a \fmod m) \cdot t + s \cdot (b \fmod m) + s\cdot m \cdot t\bigr)\cdot m\bigr) \fmod m\) \(=\bigl((a \fmod m)\cdot(b \fmod m)\bigr)\fmod m\)
Subsection Applying the properties of \(\fmod\)
Example 3.43 . Multiplication with and without Theorem 3.42.
We compute \((20\cdot 10)\fmod 7\) in two ways.
When we compute
\begin{equation*}
(10\cdot 20)\fmod 7=200\fmod 7=4\text{,}
\end{equation*}
we have to find the remainder of the division of \(200\) by \(7\text{.}\)
\((20\cdot 10)\fmod 7\) \(=\left((20\fmod 7)\cdot(10\fmod 7)\right)\fmod 7\) \(=(6\cdot 3)\fmod 7=18\fmod 7=4\)
which is longer but easier to compute, since we can easily find
\(20\fmod 7\) and
\(10\fmod 7\text{.}\)
Example 3.44 . Applying Theorem 3.38 and Theorem 3.42.
We compute
\((61+(9\cdot 12))\fmod 7\text{.}\) We first evaluate the inner parenthesis and then the outer parenthesis. By
Theorem 3.38 and
Theorem 3.42 we have
\(\left(61+(9\cdot 12)\right)\fmod 7\) \(=\left(61\fmod +\left((9 \fmod 7)\cdot (12 \fmod 7)\right)\fmod 7\right)\fmod 7\) \(= \left(5+\left((2\cdot 5)\fmod 7\right)\right)\fmod 7\) \(= \left(5+(10 \fmod 7)\right)\fmod 7\) \(=(5+3)\fmod 7 = 8 \fmod 7=1\)
Example 3.45 . Smaller but more calculations.
With Calculator long division we compute:
\(\displaystyle 8082 \fmod 17 = 7\)
\(\displaystyle 4540 \fmod 17= 1\)
\(\displaystyle 4496 \fmod 17= 8\)
Knowing these numbers and applying
Theorem 3.38 and
Theorem 3.42 we find the following without having to add or multiply large numbers.
\((8082\cdot 4540) \fmod 17 \) \(= \left((8082\fmod 17)\cdot(4540\fmod 17)\right) \fmod 17\) \(=(7\cdot 1)\fmod 17 = 7\)
\((4540+4496) \fmod 17 \) \(= \left((4540\fmod 17)\cdot(4496\fmod 17)\right) \fmod 17 \) \(= (1+8) \fmod 17 = 9\)
\((8082\cdot 4540 + 4496) \fmod 17\) \(= \left(\left((8082\cdot 4540) \fmod 17 \right)+ (4496\fmod 17)\right)\fmod 7 \) \(= (7+8)\fmod 17 = 0\)
\((8082+4540+4496)\fmod 17 \) \(= \left((8082\fmod 17)+\left((4540+4496) \fmod 17\right)\right)\fmod 17 \) \(= (7+9)=16 \fmod 17=16\)
In the following me make use of the decimal representation of numbers, to find remainders of divisions of numbers that would be to large to handle for most calculators. If you need a refresher on decimal numbers, flip ahead and read
Section 11.1 .
Problem 3.46 . \(23829913346008023471 \fmod 100\) .
Find
\(23829913346008023471 \fmod 100\text{.}\)
Solution .
First notice that
\begin{equation*}
23829913346008023471=(238299133460080234\cdot 100)+71\text{.}
\end{equation*}
\(23829913346008023471 \fmod 100 \) \(= ((238299133460080234\cdot 100)+71) \fmod 100\) \(= (((238299133460080234\cdot 100) \fmod 100)+(71 \fmod 100))\fmod 100\) \(= (0 + 71) \fmod 100 = 71\fmod 100= 71\)
Problem 3.47 . \(23829913346008023471 \fmod 1000\) .
Find
\(23829913346008023471 \fmod 1000\text{.}\)
Solution .
First notice that
\begin{equation*}
23829913346008023471=(23829913346008023\cdot 1000)+471\text{.}
\end{equation*}
\(23829913346008023471 \fmod 1000 \) \(= ((23829913346008023\cdot 1000)+471) \fmod 1000\) \(= (((23829913346008023\cdot 1000) \fmod 1000)+(471 \fmod 1000))\fmod 1000\) \(= (0 + 471) \fmod 1000 = 471\fmod 1000= 471\)
Problem 3.48 . \(23829913346008023471 \fmod 20\) .
Find
\(23829913346008023471 \fmod 20\text{.}\)
Solution .
The smallest power of
\(10\) that is divisible by
\(20\) is
\(10^2=100\text{.}\)
Now notice that
\begin{equation*}
23829913346008023471=(238299133460080234\cdot 100)+71\text{.}
\end{equation*}
\(23829913346008023471 \fmod 20 \) \(= ((238299133460080234\cdot 100)+71) \fmod 20\) \(= (((238299133460080234\cdot 100) \fmod 20)+(71 \fmod 20))\fmod 20\) \(= (0 + 71) \fmod 20 = 71\fmod 20= 11\)
Problem 3.49 . \(23829913346008023471 \fmod 5\) .
Find
\(23829913346008023471 \fmod 5\text{.}\)
Solution .
The smallest power of \(10\) that is divisible \(5\) is 10. So we write
\begin{equation*}
23829913346008023471=(2382991334600802347\cdot 10)+1\text{.}
\end{equation*}
As \(10\fmod 5=0\) we immediately see that
\begin{equation*}
23829913346008023471 \fmod 5=(0+1)\fmod 5=1.
\end{equation*}