Let \(a\) and \(b\) be integers, with \(a \neq 0\text{.}\) We say \(a\) divides \(b\text{,}\) denoted \(a \mid b\) , if there exists an integer \(k\) such that \(b = ak\text{.}\) In this case, we call \(a\) a factor of divisor of \(b\text{,}\) and \(b\) is a multiple of \(a\text{.}\) We write \(a \nmid b\) when \(a\) does not divide \(b\text{.}\)
Suppose \(a \mid b\) and \(a \mid c\text{.}\) Then there exists integers \(m\) and \(n\) such that \(b = am\) and \(c = a n\text{.}\) We want to show \(a \mid (b +
c)\text{.}\) We compute
\begin{equation*}
b + c = am + an = a(m + n).
\end{equation*}
Since \(m\) and \(n\) are integers, \(m + n\) is an integer. Thus \(a \mid
(b + c)\text{.}\)
Suppose \(a \mid b\) and \(b \mid c\text{.}\) Then there exist integers \(m\) and \(n\) such that \(b = am\) and \(c = bn\text{.}\) We want to show \(a \mid c\text{.}\) We compute
\begin{equation*}
c = bn = (am)n = a (mn).
\end{equation*}
Since \(m\) and \(n\) are integers, \(mn\) is an integer. Thus \(a \mid c\text{.}\)
Theorem5.1.1.5.Division algorithm for positive integers.
Let \(a\) and \(b\) be integers with \(b \gt 0\text{.}\) There exists unique integers \(q\) and \(r\) with \(0\leq r \lt b\) such that \(a = b\cdot q + r\text{.}\)
We now prove the uniqueness of \(q\) and \(r\text{.}\) Suppose that there are \(q_1\in\ZZ\) and \(q_2\in\ZZ\) and \(r_1\in\ZZ\) and \(r_2\in\ZZ\) such that
If \(q_1=q_2\) then \(bq_1=bq_2\text{.}\) Thus \(b\cdot q_1+r_1=b\cdot q_2+r2\) becomes \(b\cdot q_1+r_1=b\cdot q_1+r2\text{.}\) Subtracting \(b\cdot q_1\) from both sides yields \(r_1=r_2\text{.}\)
def divmod_naive(a,b):
q=0
while a>b:
a=a-b
q=q+1
return q,a
Theorem5.1.1.7.Division algorithm for negative integers.
Let \(a\) be neagtive integer and \(d\) be integers with \(d \gt 0\text{.}\) There exists unique integers \(q\) and \(r\) with \(0\leq r \lt d\) such that \(a = dq + r\text{.}\)
Let \(a\) and \(d\) be integers with \(d \gt 0\text{.}\) There exists unique integers \(q\) and \(r\) with \(0\leq r \lt d\) such that \(a = dq + r\text{.}\)
Next consider \(a = -253\) and \(d = 17\text{.}\) By long division, we see \(-253/17 \approx -14.88\text{.}\) Thus \(q = \floor{\frac{-253}{17}} = -15\text{.}\) Then \(-253 = 17(-15) + r\text{.}\) Solving for \(r\) gives \(r = 2\text{.}\)
Let \(a\) and \(d\) be integers, with \(d \gt 0\text{.}\) Let \(q\) and \(r\) be integers such that \(a = dq + r\text{,}\) with \(0 \leq r \lt d\text{.}\) We call \(d\) the divisor and we call \(a\) the dividend.
While ListingΒ 5.1.1.6 and ListingΒ 5.1.1.8 are useful for proving TheoremΒ 5.1.1.9 using repeated subtraction or addition to compute quotients and remainders when numbers are a bit larger takes a lot of subtractions or additions. Long division is much more efficient.