##### Theorem2.2.1Division Algorithm

Let \(a\) and \(b\) be integers, with \(b \gt 0\text{.}\) Then there exist unique integers \(q\) and \(r\) such that

\begin{equation*} a = bq + r \end{equation*}where \(0 \leq r \lt b\text{.}\)

An application of the Principle of Well-Ordering that we will use often is the division algorithm.

Let \(a\) and \(b\) be integers, with \(b \gt 0\text{.}\) Then there exist unique integers \(q\) and \(r\) such that

\begin{equation*} a = bq + r \end{equation*}where \(0 \leq r \lt b\text{.}\)

Let \(a\) and \(b\) be integers. If \(b = ak\) for some integer \(k\text{,}\) we write \(a \mid b\text{.}\) An integer \(d\) is called a *common divisor* of \(a\) and \(b\) if \(d \mid a\) and \(d \mid b\text{.}\) The *greatest common divisor* of integers \(a\) and \(b\) is a positive integer \(d\) such that \(d\) is a common divisor of \(a\) and \(b\) and if \(d'\) is any other common divisor of \(a\) and \(b\text{,}\) then \(d' \mid d\text{.}\) We write \(d = \gcd(a, b)\text{;}\) for example, \(\gcd( 24, 36) = 12\) and \(\gcd(120, 102) = 6\text{.}\) We say that two integers \(a\) and \(b\) are *relatively prime* if \(\gcd( a, b ) = 1\text{.}\)

Let \(a\) and \(b\) be nonzero integers. Then there exist integers \(r\) and \(s\) such that

\begin{equation*} \gcd( a, b) = ar + bs. \end{equation*}Furthermore, the greatest common divisor of \(a\) and \(b\) is unique.

Let \(a\) and \(b\) be two integers that are relatively prime. Then there exist integers \(r\) and \(s\) such that \(ar + bs = 1\text{.}\)

Among other things, Theorem Theorem 2.2.2 allows us to compute the greatest common divisor of two integers.

To compute \(\gcd(a,b) = d\text{,}\) we are using repeated divisions to obtain a decreasing sequence of positive integers \(r_1 \gt r_2 \gt \cdots \gt r_n = d\text{;}\) that is,

\begin{align*} b & = a q_1 + r_1\\ a & = r_1 q_2 + r_2\\ r_1 & = r_2 q_3 + r_3\\ & \vdots \\ r_{n - 2} & = r_{n - 1} q_{n} + r_{n}\\ r_{n - 1} & = r_n q_{n + 1}. \end{align*}To find \(r\) and \(s\) such that \(ar + bs = d\text{,}\) we begin with this last equation and substitute results obtained from the previous equations:

\begin{align*} d & = r_n\\ & = r_{n - 2} - r_{n - 1} q_n\\ & = r_{n - 2} - q_n( r_{n - 3} - q_{n - 1} r_{n - 2} )\\ & = -q_n r_{n - 3} + ( 1+ q_n q_{n-1} ) r_{n - 2} \\ & \vdots \\ & = ra + sb. \end{align*}The algorithm that we have just used to find the greatest common divisor \(d\) of two integers \(a\) and \(b\) and to write \(d\) as the linear combination of \(a\) and \(b\) is known as the *Euclidean algorithm*.

Let \(p\) be an integer such that \(p \gt 1\text{.}\) We say that \(p\) is a *prime number*, or simply \(p\) is *prime*, if the only positive numbers that divide \(p\) are 1 and \(p\) itself. An integer \(n \gt 1\) that is not prime is said to be *composite*.

Let \(a\) and \(b\) be integers and \(p\) be a prime number. If \(p \mid ab\text{,}\) then either \(p \mid a\) or \(p \mid b\text{.}\)

There exist an infinite number of primes.

Let \(n\) be an integer such that \(n \gt 1\text{.}\) Then

\begin{equation*} n = p_1 p_2 \cdots p_k, \end{equation*}where \(p_1, \ldots, p_k\) are primes (not necessarily distinct). Furthermore, this factorization is unique; that is, if

\begin{equation*} n = q_1 q_2 \cdots q_l, \end{equation*}then \(k = l\) and the \(q_i\)'s are just the \(p_i\)'s rearranged.

Prime numbers were first studied by the ancient Greeks. Two important results from antiquity are Euclid's proof that an infinite number of primes exist and the Sieve of Eratosthenes, a method of computing all of the prime numbers less than a fixed positive integer \(n\text{.}\) One problem in number theory is to find a function \(f\) such that \(f(n)\) is prime for each integer \(n\text{.}\) Pierre Fermat (1601?–1665) conjectured that \(2^{2^n} + 1\) was prime for all \(n\text{,}\) but later it was shown by Leonhard Euler (1707–1783) that

\begin{equation*} 2^{2^5} + 1 = \text{4,294,967,297} \end{equation*}is a composite number. One of the many unproven conjectures about prime numbers is Goldbach's Conjecture. In a letter to Euler in 1742, Christian Goldbach stated the conjecture that every even integer with the exception of 2 seemed to be the sum of two primes: \(4 = 2 + 2\text{,}\) \(6 = 3 + 3\text{,}\) \(8 =3 + 5\text{,}\) \(\ldots\text{.}\) Although the conjecture has been verified for the numbers up through \(4 \times 10^{18}\text{,}\) it has yet to be proven in general. Since prime numbers play an important role in public key cryptography, there is currently a great deal of interest in determining whether or not a large number is prime.

Sage's original purpose was to support research in number theory, so it is perfect for the types of computations with the integers that we have in this chapter.