Sub topic 10
Division with Remainder: \(n = dq + r\)
Assume you know basic integer arithmetic, negative numbers, zero, long division, and exponent notation. This chapter develops the division algorithm, which describes every integer division exactly.
The division algorithm
For an integer \(n\) divided by a positive integer \(d\), there are unique integers \(q\) and \(r\) such that
\[ n = dq + r \]
and
\[ 0 \le r < d. \]
Here:
- \(n\) is the dividend, or number being divided.
- \(d\) is the divisor.
- \(q\) is the quotient.
- \(r\) is the remainder.
For example,
\[ 47 = 5(9) + 2. \]
Thus, when 47 is divided by 5, the quotient is 9 and the remainder is 2.
The remainder must be less than the divisor. If a remainder were 5 or greater when dividing by 5, another group of 5 could be removed, so the quotient would not be complete.
| Division | Quotient | Remainder | Equation |
|---|---|---|---|
| \(47 \div 5\) | 9 | 2 | \(47=5(9)+2\) |
| \(36 \div 6\) | 6 | 0 | \(36=6(6)+0\) |
| \(19 \div 4\) | 4 | 3 | \(19=4(4)+3\) |
A remainder of zero means that \(d\) divides \(n\) evenly.
print(divmod(47, 5)) # (9, 2)
print(divmod(36, 6)) # (6, 0)Negative integers
The same rule applies when the dividend is negative. The remainder still satisfies \(0 \le r < d\).
For example,
\[ -7 = 5(-2) + 3. \]
Although \(-7 \div 5\) is \(-1.4\), the quotient in the division algorithm is \(-2\), because this produces a nonnegative remainder smaller than 5.
Working with remainders
If
\[ a = dq1+r1 \quad\text{and}\quad b = dq2+r2, \]
then the remainder of \(a+b\) after division by \(d\) is the remainder of \(r1+r2\). Similarly, the remainder of \(ab\) is the remainder of \(r1r2\).
For example, modulo 5,
\[ 17 \text{ has remainder }2,\qquad 23 \text{ has remainder }3. \]
Therefore,
\[ 17\cdot23 \]
has the same remainder as
\[ 2\cdot3=6, \]
which leaves remainder 1 when divided by 5.
This method is useful when the original numbers are large.
a, b, d = 17, 23, 5
print((a * b) % d) # 1
print(((a % d) * (b % d)) % d) # 1The same principle works for sums and differences. Reduce each number first, then perform the simpler operation. If the result is negative, add the divisor until the standard remainder range is reached.
GRE strategy
For a numeric entry or quantitative comparison question:
- Write \(n=dq+r\).
- Use \(0\le r<d\) to limit possible remainders.
- Replace large numbers with their remainders before multiplying or adding.
- Test whether the question asks for a particular quotient, remainder, or divisibility condition.
Exercise
If an integer \(n\) leaves remainder 4 when divided by 7, what remainder does \(3n+5\) leave when divided by 7?
Show answer
Replace \(n\) with 4: \(3n+5\) has the same remainder as \(3(4)+5=17\). Since 17 leaves remainder 3 when divided by 7, the answer is 3.