Skip to main content
Logo image

Section 3.4 The Operation mod

In this section we investigate the properties of the operation mod 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.37 we give an overview of the properties of mod covered in this section.
Figure 3.37. The operation mod by Matt Farmer and Stephen Steward
Before we get to the properties we recall how to compute mod and make some observations about the behavior of mod.

Subsection Computing mod

Recall that amodb is the remainder of the division of a by b (see Definition 3.21). We have established that the division algorithm (Algorithm 3.6 and Algorithm 3.14) 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.38. Three methods for computing 41mod13.

We compute 41mod13 in three different ways. The number 41mod13 is the remainder of the division of 41 by 13.
  • 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÷13=3.153. So the quotient from the decision of 41 by 13 is the largest integer that is less than 3.153, which is 3. The remainder is 41313=4139=2. Thus 41mod13=2.
  • Method 3 division algorithm.
    We subtract 13 until we get a number in the remainder target range from 0 to 131=12:
    4113=282813=151513=2
    As 2 is in the remainder target range from 0 to 131=12 it is the remainder. Thus 41 mod 13 = 2.

Example 3.39. Three methods for computing 41mod13.

We compute 41mod13 in three different ways. The number 41mod13 is the remainder of the division of 41 by 13.
  • Method 1 the trained eye.
    The smallest multiple of 13 that is greater than 41 is 52. The sum of 41 and 52 is 11, this is the remainder of the division of 41 by 13. Thus 41mod13=11.
  • Method 2 calculator long division.
    We have 41÷13=3.153. So the quotient of the division of 41 by 13 is the largest integer that is less than 3.153 which is 4. The remainder is 41+413=41+52=11. Thus 41mod13=11.
  • Method 3 division algorithm.
    We add 13 until we get a number in the remainder target range from 0 to 131=12:
    41+13=2828+13=1515+13=22+13=11
    As 11 is in the remainder target range from 0 to 131=12 it is the remainder. Thus -41 mod 13 = 11.
The three methods are also subject of the video in Figure 3.40.
Figure 3.40. How to compute mod 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.41. Integers modulo three.

0mod3=01mod3=12mod3=23mod3=04mod3=15mod3=26mod3=07mod3=18mod3=2

Example 3.42. Integers modulo two.

0mod2=01mod2=12mod2=03mod2=14mod2=05mod2=16mod2=07mod2=18mod2=0
The remainder of division by 2 is an integer that is greater than or equal to 0 and less than 2, that is, it is either 0 or 1. We use this to define two familiar terms.

Definition 3.43.

An integer n is even means that nmod2=0.

Definition 3.44.

An integer n is odd means that nmod2=1.

Subsection Properties of mod

We now investigate some properties of the operation mod. In particular, we are interested in the behavior of mod in sums and products.
To get an idea how mod behaves under addition we look at an example.

Example 3.45. Addition and mod.

We have
(11+5)mod7=16mod7=2.
Let’s try we whether we can distribute mod over the addition.
(11mod7)+(5mod7)=4+5=9.
We see that
(11mod7)+(5mod7)(11+5)mod7.
But we notice that 9mod7=2. So computing mod7 once more will yield equality:
((11mod7)+(5mod7))mod7=(4+5)mod7=11mod7=2.
So, we have
((11mod7)+(5mod7))mod7=(11+5)mod7.
We build upon our observations in the example to formulate a theorem about addition in combination with the operation mod.

Proof.

We have that
a=(amodm)+(sm) for some integer s, and b=(bmodm)+(tm) for some integer t.
With the notation above, we have
(a+b)modm =(((amodm)+(sm))+((bmodm)+(tm)))modm =((amodm)+(bmodm)+(s+t)m)modm =((amodm)+(bmodm))modm

Example 3.47. Addition with and without Theorem 3.46.

We illustrate Theorem 3.46 with an example. We compute (10+20)mod7 in two ways, namely directly and applying the theorem.
  1. (10+20)mod7=30mod7=2
  2. (10+20)mod7=((10mod7)+(20mod7))mod7=(3+6)mod7=9mod7=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.48. Apply Theorem 3.46.

Let a and b be integers with amod113=29 and bmod113=100. Compute (a+b)mod113.
Solution.
By Theorem 3.46 we have
(a+b)mod113=((amod113)+(bmod113))mod113
As we know that amod113=29 and bmod113=100 we can replace amod113 by 29 and bmod113 by 100. Copying what we have so far and evaluating we get:
(a+b)mod113 =((amod113)+(bmod113))mod113 =(29+100)mod113 =129mod113=16
.
Next we explore how multiplication and mod interact.

Example 3.49. Multiplication and mod.

We have
(115)mod7=55mod7=6.
Let’s try we whether we can distribute mod over the addition.
(11mod7)(5mod7)=45=20.
We see that
(11mod7)(5mod7)(115)mod7.
But we notice that 20mod7=6. So computing mod7 once more will yield equality:
((11mod7)(5mod7))mod7=(45)mod7=20mod7=3.
So, we have
((11mod7)(5mod7))mod7=(115)mod7.
The observations made in the example suggests that a theorem analogous to Theorem 3.46 holds for multiplication. Indeed we have:

Proof.

There are integers s and t such that
a=(amodm)+(sm)
and
b=(bmodm)+(tm).
Thus (ab)modm =(((amodm)+sm)((bmodm)+tm))modm =((amodm)(bmodm) +(amodm)tm+sm(bmodm)+smtm)modm =((amodm)(bmodm) +((amodm)t+s(bmodm)+smt)m)modm =((amodm)(bmodm))modm
In Checkpoint 3.51 decide whether statements about mod are true or false. If the statement is false give a counterexample, otherwise leave the box empty.

Checkpoint 3.51. Properties of mod.

Decide whether the following statements are true or false. If the statement is false give a counterexample, otherwise leave the box empty.
(1)
  • select
  • The statement is true
  • The statement is false
For all integers a and b we have (ab)mod6=((amod6)(bmod6))mod6
Counterexample: The statement is false, because for the integer a= we have (a5)mod6((amod6)(5mod6))mod6.
(2)
  • select
  • The statement is true
  • The statement is false
For all integers a and b we have (a+b)mod20=(amod20)+(bmod20)
Counterexample: The statement is false, because for the integer a= we have (a+5)mod20(amod20)+(5mod20).
(3)
  • select
  • The statement is true
  • The statement is false
For all integers a and all b we have (a+b)mod6=a+b
Counterexample: The statement is false, because for the integer a= we have (a+3)mod6a+3.

Subsection Applying the properties of mod

Theorem 3.46 and Theorem 3.50 are particularly useful when computing mod with larger numbers.

Example 3.52. Multiplication with and without Theorem 3.50.

We compute (2010)mod7 in two ways.
  1. When we compute
    (1020)mod7=200mod7=4,
    we have to find the remainder of the division of 200 by 7.
  2. With Theorem 3.50 we get
    (2010)mod7 =((20mod7)(10mod7))mod7 =(63)mod7=18mod7=4
    which is longer but easier to compute, since we can easily find 20mod7 and 10mod7.

Example 3.53. Applying Theorem 3.46 and Theorem 3.50.

We compute (61+(912))mod7. We first evaluate the inner parenthesis and then the outer parenthesis. By Theorem 3.46 and Theorem 3.50 we have
(61+(912))mod7 =(61mod+((9mod7)(12mod7))mod7)mod7 =(5+((25)mod7))mod7 =(5+(10mod7))mod7 =(5+3)mod7=8mod7=1

Example 3.54. Smaller but more calculations.

With Calculator long division we compute:
  1. 8082mod17=7
  2. 4540mod17=1
  3. 4496mod17=8
Knowing these numbers and applying Theorem 3.46 and Theorem 3.50 we find the following without having to add or multiply large numbers.
  1. (80824540)mod17 =((8082mod17)(4540mod17))mod17 =(71)mod17=7
  2. (4540+4496)mod17 =((4540mod17)(4496mod17))mod17 =(1+8)mod17=9
  3. (80824540+4496)mod17 =(((80824540)mod17)+(4496mod17))mod7 =(7+8)mod17=0
  4. (8082+4540+4496)mod17 =((8082mod17)+((4540+4496)mod17))mod17 =(7+9)=16mod17=16
In Checkpoint 3.55 apply properties the properties of mod to conduct computations modulo a given integer, when the values are only known modulo that integer.

Checkpoint 3.55. Apply properties of mod.

Let a be an integer.
Suppose that the remainder when a is divided by 6 is 0 and the remainder when b is divided by 6 is 2.
That is, a mod 6=0 and b mod 6=2.
Find:
(a+a) mod 6 =
(a+b) mod 6 =
(ab) mod 6 =
(a+5) mod 6 =
(5b) mod 6 =
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.56. 23829913346008023471mod100.

Find 23829913346008023471mod100.
Solution.
First notice that
23829913346008023471=(238299133460080234100)+71.
With Theorem 3.46 and 100mod100=0 we get:
23829913346008023471mod100 =((238299133460080234100)+71)mod100 =(((238299133460080234100)mod100)+(71mod100))mod100 =(0+71)mod100=71mod100=71

Problem 3.57. 23829913346008023471mod1000.

Find 23829913346008023471mod1000.
Solution.
First notice that
23829913346008023471=(238299133460080231000)+471.
With Theorem 3.46 and 1000mod1000=0 we get:
23829913346008023471mod1000 =((238299133460080231000)+471)mod1000 =(((238299133460080231000)mod1000)+(471mod1000))mod1000 =(0+471)mod1000=471mod1000=471

Problem 3.58. 23829913346008023471mod20.

Find 23829913346008023471mod20.
Solution.
The smallest power of 10 that is divisible by 20 is 102=100.
Now notice that
23829913346008023471=(238299133460080234100)+71.
With Theorem 3.46 and 100mod20=0 we get:
23829913346008023471mod20 =((238299133460080234100)+71)mod20 =(((238299133460080234100)mod20)+(71mod20))mod20 =(0+71)mod20=71mod20=11

Problem 3.59. 23829913346008023471mod5.

Find 23829913346008023471mod5.
Solution.
The smallest power of 10 that is divisible 5 is 10. So we write
23829913346008023471=(238299133460080234710)+1.
As 10mod5=0 we immediately see that
23829913346008023471mod5=(0+1)mod5=1.
Try for yourself in Checkpoint 3.60.

Checkpoint 3.60. Large numbers and mod.

We can write 2011317099= 100+
Because 99mod2 = we have 2011317099mod2 = .
Because 99mod4 = we have 2011317099mod4 = .
Because 99mod5 = we have 2011317099mod5 = .
Because 99mod10 = we have 2011317099mod10 = .
Because 99mod20 = we have 2011317099mod20 = .
Because 99mod25 = we have 2011317099mod25 = .
Because 99mod100 = we have 2011317099mod100 = .
Hint.
Example: 1234567=12345100+67
In the following each ? can be any number from 0 to 9.
We have
2011317099mod10=9mod10
Thus, because 2 and 5 divide 10, also
2011317099mod2=9mod2 and
2011317099mod5=9mod5
Similarly
2011317099mod100=99mod100
Thus, because 4 and 20 and 25 divide 100, also
2011317099mod4=99mod4 and
2011317099mod20=99mod20 and
2011317099mod25=99mod25.