Divisibility and the Division Algorithm
Divisibility describes when one integer goes into another evenly: a divides b, written a | b, when b = ak for some integer k. The division algorithm says that for any integer a and any positive integer d, there are unique integers q and r with a = dq + r and 0 ≤ r < d.
Before this lesson: Direct Proof, Proof by Contradiction and, from Pre-Algebra, Prime Factorization
What divisibility means
Number theory is the study of the integers, and its first question is whether one integer is a multiple of another. In this lesson every letter stands for an integer.
a \mid b \iff b = ak \text{ for some integer } k \quad (a \ne 0)Read a | b as “a divides b.” Then a is a divisor (or factor) of b, and b is a multiple of a. If no such integer k exists, write a ∤ b. For example, 4 | 28 because 28 = 4 · 7, and −3 | 15 because 15 = (−3)(−5).
The symbol a | b is a statement, true or false. It is not a number. The fraction a/b is a number, and the vertical bar points the other way: 4 | 28 is true, while 28/4 = 7.
Properties of divisibility
| Property | Statement | Why it holds |
|---|---|---|
| Every nonzero integer divides 0 | a ∣ 0 for every a ≠ 0 | 0 = a · 0 |
| 1 and a divide a | 1 ∣ a, and a ∣ a when a ≠ 0 | a = 1 · a = a · 1 |
| Transitive property | If a ∣ b and b ∣ c, then a ∣ c | c = bl = (ak)l = a(kl) |
| Linear combinations | If a ∣ b and a ∣ c, then a ∣ (mb + nc) for all integers m and n | mb + nc = a(mk + nl) |
| Size | If a ∣ b and b ≠ 0, then |a| ≤ |b| | |b| = |a| · |k| and |k| ≥ 1 |
Each property has a short direct proof from the definition. Here is the proof of the linear-combination property, which is used most often.
a \mid b \Rightarrow b = ak
Write the first hypothesis with the definition, for some integer k.
a \mid c \Rightarrow c = al
Write the second hypothesis, for some integer l.
mb + nc = m(ak) + n(al)
Substitute both expressions.
mb + nc = a(mk + nl)
Factor out a (see distributive property).
mk + nl \in \mathbb{Z}Sums and products of integers are integers.
a \mid (mb + nc)
The expression is a times an integer, which matches the definition.
The division algorithm
When d does not divide a, the division leaves something over. The division algorithm makes “something over” precise.
a = dq + r, \qquad 0 \le r \lt d
Here a is the dividend, d \gt 0 is the divisor, q is the quotient and r is the remainder. Many books write q = a div d and r = a mod d. The quotient is the floor of a/d, the greatest integer less than or equal to a/d.
q = \left\lfloor \dfrac{a}{d} \right\rfloor, \qquad r = a - dqOn a number line, dq is the multiple of d at or just below a, and r is the distance from that multiple up to a. So d | a exactly when r = 0.
Why q and r are unique. Suppose a = dq + r = dq′ + r′ with both remainders between 0 and d − 1. Subtracting gives d(q − q′) = r′ − r. The right side is strictly between −d and d, and the left side is a multiple of d, so both sides are 0. Then q = q′ and r = r′.
Division algorithm examples
Example 1: Checking divisibility
Decide whether 7 | 91, whether 6 | 74 and whether −8 | 56.
7 \cdot 13 = 91
Multiply to test k = 13.
7 \mid 91
91 = 7k with k = 13, an integer.
6 \cdot 12 = 72
Find the multiple of 6 just below 74.
6 \cdot 13 = 78
Find the next multiple of 6.
72 \lt 74 \lt 78
74 lies strictly between consecutive multiples, so 74 = 6k has no integer solution k.
6 \nmid 74
Conclude that 6 does not divide 74.
(-8)(-7) = 56
A negative times a negative is positive (see multiplying and dividing integers).
-8 \mid 56
56 = (−8)k with k = −7, an integer.
Answer: 7 | 91, 6 ∤ 74 and −8 | 56. A negative divisor works the same way as a positive one.
Example 2: Quotient and remainder
Use the division algorithm to find q and r when a = 157 and d = 12.
\dfrac{157}{12} \approx 13.08Divide to estimate the quotient.
q = \lfloor 13.08 \rfloor = 13
Take the floor: round down to an integer.
12 \cdot 13 = 156
Multiply the divisor by the quotient.
r = 157 - 156 = 1
Subtract to get the remainder.
0 \le 1 \lt 12
Check that the remainder is in range.
157 = 12 \cdot 13 + 1
Write the result in the form a = dq + r.
Answer: q = 13 and r = 1, so 157 div 12 = 13 and 157 mod 12 = 1.
Example 3: A negative dividend
Find q and r when a = −53 and d = 8.
\dfrac{-53}{8} = -6.625Divide.
q = \lfloor -6.625 \rfloor = -7
Round down, toward −∞. Rounding toward 0 would give −6.
8 \cdot (-7) = -56
Multiply the divisor by the quotient.
r = -53 - (-56)
Subtract dq from a.
r = -53 + 56 = 3
Subtracting a negative adds its opposite (see adding and subtracting integers).
0 \le 3 \lt 8
Check that the remainder is in range.
-53 = 8(-7) + 3
Write the result in the form a = dq + r.
Answer: q = −7 and r = 3. The choice q = −6 would give −53 = 8(−6) − 5, but a remainder of −5 breaks the rule 0 ≤ r < d.
Example 4: What day of the week? (word problem)
Today is Thursday. What day of the week will it be 200 days from now?
\dfrac{200}{7} \approx 28.57The days repeat every 7, so divide by d = 7.
q = 28
Take the floor: 28 full weeks.
7 \cdot 28 = 196
Multiply the divisor by the quotient.
r = 200 - 196 = 4
Subtract to get the remainder.
200 = 7 \cdot 28 + 4
The 28 full weeks end on a Thursday again.
\text{Thu} \to \text{Fri} \to \text{Sat} \to \text{Sun} \to \text{Mon}Count forward the remaining 4 days.
Answer: Monday. Only the remainder matters, because whole weeks bring you back to the same day.
Example 5: Squares leave remainder 0 or 1 when divided by 4
Prove that for every integer n, the remainder when n² is divided by 4 is 0 or 1.
n = 2k \text{ or } n = 2k + 1Division algorithm with d = 2: the remainder is 0 or 1, for some integer k.
n^2 = (2k)^2
Case 1: n = 2k. Substitute.
n^2 = 4k^2
Square the product.
n^2 = 4(k^2) + 0
This is a = dq + r with d = 4, q = k² and r = 0.
n^2 = (2k + 1)^2
Case 2: n = 2k + 1. Substitute.
n^2 = 4k^2 + 4k + 1
Expand the square (see special products of binomials).
n^2 = 4(k^2 + k) + 1
Factor 4 out of the first two terms. Here q = k² + k and r = 1.
Answer: every square leaves remainder 0 or 1, never 2 or 3, when divided by 4. For example, 4,000,003 = 4 · 1,000,000 + 3 leaves remainder 3, so it cannot be a perfect square.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Treating a | b as a number | “12 | 4 = 3” | a | b is a statement. 4 | 12 is true and 12 ∤ 4. |
| Reversing the roles | “3 | 12 means 3 is a multiple of 12.” | a | b means b is the multiple: 12 = 3 · 4. |
| Rounding a negative quotient toward 0 | −53 = 8(−6) − 5 | Round down: q = −7 and r = 3, since 0 ≤ r < d. |
| Leaving a remainder that is too big | 157 = 12 · 12 + 13 | If r ≥ d, raise q by 1: 157 = 12 · 13 + 1. |
| Reversing the linear-combination property | “3 | (4 + 5), so 3 | 4 and 3 | 5.” | The property only goes one way. 3 divides the sum but neither term. |
| Trusting a calculator’s % key | In some languages, −53 % 8 returns −5 | Check that 0 ≤ r < d. If r is negative, add d and lower q by 1. |
Related ideas
Polynomials have their own division algorithm, f(x) = d(x)q(x) + r(x) with the degree of r less than the degree of d, which is what polynomial long division computes. The remainder and factor theorems are the polynomial versions of “r = 0 means d divides a.”
Divisibility is also the language behind the greatest common factor and the least common multiple. The next lesson, Euclidean Algorithm, uses the division algorithm over and over to find the greatest common divisor quickly, and the lesson after it, Modular Arithmetic, does arithmetic with remainders.
Practice problems
- Does 9 | 153?
- Does −6 | 87?
- Find q and r when a = 250 and d = 17.
- Find q and r when a = −100 and d = 7.
- Find q and r when a = 45 and d = 50.
- Find q and r when a = −36 and d = 9. What does r tell you?
- Find 1000 div 13 and 1000 mod 13.
- Prove that if a | b, then a | bc for every integer c.
- Prove the transitive property: if a | b and b | c, then a | c.
- A bakery packs 500 cookies into boxes of 24. How many boxes are full, and how many cookies are left over?
Show answers
1.
9 \cdot 17 = 153
Multiply to test k = 17.
Answer: yes, 9 | 153 because 153 = 9 · 17
2.
6 \cdot 14 = 84
Find the multiple of 6 just below 87.
6 \cdot 15 = 90
Find the next multiple of 6.
84 \lt 87 \lt 90
87 lies strictly between consecutive multiples of 6, so it is not a multiple of 6 or of −6.
Answer: no, −6 ∤ 87
3.
\dfrac{250}{17} \approx 14.71Divide to estimate the quotient.
q = 14
Take the floor.
17 \cdot 14 = 238
Multiply the divisor by the quotient.
r = 250 - 238 = 12
Subtract to get the remainder.
250 = 17 \cdot 14 + 12
Check: 0 ≤ 12 < 17.
Answer: q = 14 and r = 12
4.
\dfrac{-100}{7} \approx -14.29Divide.
q = \lfloor -14.29 \rfloor = -15
Round down, toward −∞.
7 \cdot (-15) = -105
Multiply the divisor by the quotient.
r = -100 - (-105)
Subtract dq from a.
r = -100 + 105 = 5
Subtracting a negative adds its opposite.
-100 = 7(-15) + 5
Check: 0 ≤ 5 < 7.
Answer: q = −15 and r = 5
5.
\dfrac{45}{50} = 0.9Divide.
q = \lfloor 0.9 \rfloor = 0
Take the floor.
r = 45 - 50 \cdot 0 = 45
Subtract dq from a.
45 = 50 \cdot 0 + 45
Check: 0 ≤ 45 < 50.
Answer: q = 0 and r = 45. When 0 ≤ a < d, the remainder is a itself
6.
\dfrac{-36}{9} = -4Divide. The result is already an integer.
q = -4
The floor of an integer is the integer itself.
r = -36 - 9(-4) = -36 + 36 = 0
Subtract dq from a.
Answer: q = −4 and r = 0. A remainder of 0 means 9 | −36
7.
\dfrac{1000}{13} \approx 76.92Divide to estimate the quotient.
q = 76
Take the floor.
13 \cdot 76 = 988
Multiply the divisor by the quotient.
r = 1000 - 988 = 12
Subtract to get the remainder.
Answer: 1000 div 13 = 76 and 1000 mod 13 = 12, since 1000 = 13 · 76 + 12
8.
b = ak
Write a | b with the definition, for some integer k.
bc = (ak)c
Multiply both sides by c.
bc = a(kc)
Regroup with the associative property.
kc \in \mathbb{Z}A product of integers is an integer.
Answer: bc is a times an integer, so a | bc
9.
b = ak
Write a | b with the definition, for some integer k.
c = bl
Write b | c with the definition, for some integer l.
c = (ak)l
Substitute ak for b.
c = a(kl)
Regroup with the associative property.
kl \in \mathbb{Z}A product of integers is an integer.
Answer: c is a times an integer, so a | c
10.
\dfrac{500}{24} \approx 20.83Divide by the box size.
q = 20
Take the floor: 20 full boxes.
24 \cdot 20 = 480
Multiply to count the cookies in full boxes.
r = 500 - 480 = 20
Subtract to get the leftover cookies.
500 = 24 \cdot 20 + 20
Check: 0 ≤ 20 < 24.
Answer: 20 full boxes, with 20 cookies left over
Division algorithm FAQ
What does a | b mean in math?
It means a divides b: there is an integer k with b = ak. For example, 5 | 35 because 35 = 5 · 7. It is a true-or-false statement, not a fraction.
Can the remainder in the division algorithm be negative?
No. The division algorithm requires 0 ≤ r < d. For a negative dividend, round the quotient down: −53 = 8(−7) + 3, so the remainder is 3, not −5.
What is the difference between div and mod?
For a = dq + r with 0 ≤ r < d, a div d is the quotient q and a mod d is the remainder r. For example, 157 div 12 = 13 and 157 mod 12 = 1.
Is 0 divisible by every integer?
Every nonzero integer divides 0, because 0 = a · 0. Under the definition used here, the divisor must be nonzero, so 0 is never used as a divisor.
Summary
- a | b means b = ak for some integer k. It is a statement, not a number.
- Divisibility is transitive, and a divisor of b and c also divides every combination mb + nc.
- Division algorithm: for any integer a and positive integer d, there are unique q and r with a = dq + r and 0 ≤ r < d.
- The quotient is q = ⌊a/d⌋, and the remainder is r = a − dq. Round down even when a is negative.
- d | a exactly when the remainder r is 0.
Previous lesson: Countable and Uncountable Sets
Next lesson: Euclidean Algorithm
Back to the Discrete Math Index