Let \(a, b \in \mathbb{Z}\). \(a\) divides \(b\) or \(a \mid b\) if there exists an \(m \in \mathbb{Z}\) such that \(am = b\).

Note: \(a \mid b\) doesn’t mean that \(\frac{b}{a}\) is defined. Also note that \(a \mid 0\) is only true if \(a = 0\).

Example

Show that \(6 \ | \ n(n+1)(n+2)\).

Proof: One way to see this is to observe that \(n(n+1)\) is an even number since if \(n\) is odd, then \(n+1\) is even so the product is even. Otherwise \(n\) is even so the product is even again. Therefore, \(n(n+1)\) is divisible by 2. Also observe that \(n(n+1)(n+2)\) must be divisible by 3. This is because say \(n\) leaves a remainder of 1 when divided by 3, then \(n+2\) is divisible by 3. If \(n\) leaves a remainder of 2, then \(n+1\) is divisible by 3. So in a set of 3 consecutive integers, we will always have one of them divisible by 3. So now 2 and 3 are coprime so the product must be divisible by 6. (This fact isn’t obvious and needs a proof)
Another way to show this to recognize that this product is the binomial coefficient

$$ \begin{align*} \binom{n+2}{3} = \frac{n(n+1)(n+2)}{6} \end{align*} $$

This is obviously an integer so \(n(n+1)(n+2)\) must be divisible by 6.

Example

Show that \(8 \ | \ n^2 - 1\) if \(n\) is odd.

Proof: Since \(n\) is odd, then we can write \(n = 2k+1\) for some integer \(k\). So now we can expand \(n^2 - 1\) to see that

$$ \begin{align*} n^2 - 1 &= (2k+1)^2 - 1 \\ &= 4k^2 + 4k + 1 - 1 \\ &= 4(k^2 + k) = 4(k(k+1)) \end{align*} $$

Recall that \(k(k+1)\) is even. So it is divisible by 2. Therefore, we can re-write the previous expression as

$$ \begin{align*} 4(k(k+1)) &= 8\frac{k(k+1)}{2} \end{align*} $$

From this we see that \(n^2 - 1\) is divisible by 8.


Euclid's Divison Algorithm

Given integers \(a,b > 0\), then exists unique integers \(q\) and \(r\) such that $$ \begin{align*} b = qa + r \end{align*} $$ where \(0 \leq r < a\).

Proof: TODO (number line)


Ideals in \(\mathbb{Z}\)

Given some \(d \in \mathbb{Z}\), the set of all \(x\) such that \(d \mid x\) forms an ideal in \(\mathbb{Z}\) that is closed under addition and subtraction. Conversely, given an ideal \(I\) in \(\mathbb{Z}\), then \(I\) is the set of multiples of some number \(d \geq 0\).

To show this, we can use Euclid’s division algorithm. So suppose \(I\) is an ideal, then either \(I = \{0\}\) and we’re done or \(I\) contains an element \(a > 0\). Pick the smallest positive element \(a\) in \(I\) (By the well ordering principle, this exists). We will show that \(I\) is generated by \(a\) so \(I = (a)\). To see this, let \(b\) be an element in \(I\). Apply Euclid’s division algorithm to write \(b = qa + r\) where \(q, r \in \mathbb{Z}\) and \(0 < r \leq a\). Write \(r = b - qa\). Observe that \(qa \in I\) since \(a \in I\) and any multiple of \(a\) must be in \(I\). We also know that \(b \in I\). Therefore, \(r\) must be in \(I\) since \(I\) is closed under subtraction. But this is a contradiction since we assumed that \(a\) is the smallest positive element in \(I\) and \(r < a\). Therefore, we must have \(r = 0\). So \(b = qa\) which means that \(b\) is a multiple of \(a\). So \(I = (a)\) as we wanted to show. \(\ \blacksquare\)


The Greatest Common Divisor

Unlike what we learned in Math417, the greatest common divisor here is defined as the largest integer \(d\) such that \(d \mid a\) and \(d \mid b\). Though the professor does note that when \(a = b = 0\), then we define \(gcd(a,b)=0\) and here the gcd is not the largest. Also note that \(gcd(a,0)=a\) for any \(a\).

How do we find the greatest common divisor of two integers \(a\) and \(b\)? the naive way is to check all the numbers from \(1\) to \(a\) and see if any divides \(b\), then pick the largest one. This method is obviously too slow.

A better method is factoring both \(a\) and \(b\) into primes and then picking the all the common primes. So if \(a = 24 = 2^3(3)\) and \(b = 180 = 2^2(3^2)5\). Then the greatest common divisor is \(2^2(3) = 12\). The problem with this method is factoring large numbers is a difficult problem.


Euclid's Algorithm

The fastest way to compute the greatest common divisor is Euclid’s Algorithm. Suppose we’re trying to find the greatest common divisor of 78 and 14. Then we use division with remainder where in each iteration, we divide again the quotient by the remainder from the previous step. We stop the algorithm when the last remainder is 0. So

$$ \begin{align*} 78 &= 14 \cdot 5 + 8 \\ 14 &= 8 \cdot 1 + 6 \\ 8 &= 6 \cdot + 2 \\ 6 &= 2 \cdot 3 + 0. \end{align*} $$

The greatest common divisor in this case is 2. This works because \((78,14) = (14,8) = (8,6) = (6, 2) = (2, 0) = 2\). Moreover, this algorithm terminates since the remainders are decreasing positive integers \(8, 6, 2, 0\). Generally, given integers \(a\) and \(b\)

$$ \begin{align*} a &= q_1 \cdot b + r_1 \\ b &= q_2 \cdot r_1 + r_2 \\ r_1 &= q_3 \cdot r_2 + r_3 \\ r_2 &= q_4 \cdot r_3 + r_4 \\ &\cdots \\ r_{n-1} &= q_{n+1} \cdot r_{n} + r_{n+1} \end{align*} $$

The greatest common divisor will be \(r_n\). What is the worst case? The worst case happens when all the quotients in every step are 1. For example take the integers 13 and 8 and observe that

$$ \begin{align*} 13 &= 8 \cdot 1 + 5 \\ 8 &= 5 \cdot 1 + 3 \\ 5 &= 3 \cdot 1 + 2 \\ 3 &= 2 \cdot 1 + 1 \\ 2 &= 1 \cdot 1 + 0 \end{align*} $$

The greatest common divisor is 1 and you can see that \(q=1\) in every step. To find out the number of steps, notice here that each remainder is the sum of the next two remainders. So \(r_i = r_{i+1} + r_{i+2}\). And in the worst case specifically, notice that if we work backward, then we get the sequence

$$ \begin{align*} 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... \end{align*} $$

This is the fibonacci sequence and this happens in the worst case for Euclid’s algorithm. To get a sense of how fast this sequence growth notice that

Sequence0112358\(\cdots\)
Upper Bound012481632\(\cdots\)
Lower Bound0112244\(\cdots\)

From this we see that \(F_n\) is bounded below and above by

$$ \begin{align*} 2^{n/2} &\leq F_n \leq 2^n \\ \frac{n}{2}\log(2) &\leq \log(F_n) \leq \log(2)n \end{align*} $$

Again

  • \(n\) is the number of steps in Euclid's algorithm.
  • \(n\) is also the index of the \(n\)th term Fibonacci sequence.

We’re interested in a bound on \(n\), so we want a bound on the \(n\)th fibonacci number. Using the above inequality, we see that

$$ \begin{align*} \frac{n}{2}\log(2) &\leq \log(F_n) \\ n &\leq c\log(F_n) \quad \text{ for some constant } c \end{align*} $$

So \(n\) is at most \(c\log(F_n)\) where \(c\) is a constant. Therefore, in the worst case, the number of steps in Euclid’s algorithm is bounded above by a constant times the number of digits in that \(n\)th Fibonacci number. For example, if one of the numbers has a 1000 digits, then Euclid’s algorithm will take at most 1000 iterations (times a constant) in the worst case.


Solving \(ax + by = d\)

We can use also Euclid’s algorithm to solve equations like 71x + 17y = 1. The first thing we want to do is to find the gcd of 71 and 17 using Euclid’s algorithm. So

$$ \begin{align*} 71 &= 17 \cdot 4 + 3 \\ 17 &= 3 \cdot 5 + 2 \\ 3 &= 2 \cdot 1 + 1 \\ 2 &= 1 \cdot 2 + 0 \end{align*} $$

The greatest common divisor in this case is 1. So now we work backwards. Starting from the greatest common divisor 1, we look at the previous equation and we write 1 in terms of 3 and 2 to get

$$ \begin{align*} 1 &= 3 - 1 \cdot 2 \end{align*} $$

Next, we write 2 in terms of the previous equation

$$ \begin{align*} 1 &= 3 - 1 \cdot (17 - 5 \cdot 3) \\ &= 3 - 1 \cdot 17 + 5 \cdot 3 \\ &= 6 \cdot 3 - 1 \cdot 17 \\ \end{align*} $$

Now, we look at the equation before that (the first equation) and write 3 above in terms of it

$$ \begin{align*} 1 &= 6 \cdot 3 - 1 \cdot 17 \\ &= 6 \cdot (71 - 17 \cdot 4) - 1 \cdot 17 \\ &= 6 \cdot 71 - 17 \cdot 24 - 1 \cdot 17 \\ &= 6 \cdot 71 - 17 \cdot 25 \\ \end{align*} $$

Therefore, the solution is \(x = 6\) and \(y = -25\).

Suppose now that we want to solve \(72x + 26y = 1\). We should immediately notice that since both 72 and 26 are even, then there can’t be a solution satisfying this. In general, if \(ax + by = c\) is solvable and we have that \(d \mid a\) and \(d \mid b\), then we must have \(d \mid c\) as well. In particular, \(c\) must be divisible by the greatest common divisor of \(a\) and \(b\). Conversely, if \((a,b) \ | \ c\), then the equation is solvable. This is because we know that the greatest common divisor can be written as a linear combination of \(a\) and \(b\).


Linear Equations in 3 Variables

What about solving a linear equation in 3 variables. For example

$$ \begin{align*} 6x + 10y + 15z = 1 \end{align*} $$

We first solve the following equation using Euclid’s method

$$ \begin{align*} 6x + 10y &= (6,10) = 2 \end{align*} $$

The solution for this is \(x = 2\) and \(y = -1\) so \(6 \cdot 2 - 1 \cdot 10 = 2\). Next, we solve

$$ \begin{align*} 2w + 15z &= 1. \end{align*} $$

The solution for this is \(x = -7\) and \(y = 1\). At this point, we can substitute the solution from the first equation into the solution we have

$$ \begin{align*} 2 \cdot -7 + 15 \cdot 1 &= 1 \\ (6 \cdot 2 + 10 \cdot -1) \cdot -7 + 15 \cdot 1 &= 1 \\ 6 \cdot -15 + 10 \cdot 7 + 15 \cdot 1 &= 1 \end{align*} $$

In general, \(ax + by + cz = n\) has a solution if and only if \((a,b,c) \mid n\). This method also works for equations in \(n\) variables.


Alternative to Long Division

We still have an issue with Euclid’s algorithm because long division is slow and complicated when the numbers have hundreds of digits. So a better algorithm is to avoid long division. Instead, we do the following to find the greatest common divisor of \(a\) and \(b\)

  1. Take out all factors of 2 from \(a\) and \(b\). This is easy to do since it's a simple shift operator. So now both \(a\) and \(b\) are odd. Also we can assume that \(a > b\), otherwise swap them.
  2. Change \(a\) to \(a - b\). If the result \(a - b\), we stop. Otherwise notice here that \(a\) is even so it at least have a factor of \(2\).
  3. Take all factors of 2 from \(a\). Go back to step 2.

Since we keep dividing by 2, this algorithm is still fast and the number of steps is approximately \(c\log(a)\) where \(c\) is some constant.

Example

Suppose we want to find the greatest common divisor of 68 and 142. Then we take out the factors of 2 out. So 68 becomes 34 and then 17. While 141 becomes 71. Notice how there is a common factor of 2 between the two numbers. Next, we find the greatest common divisor of 71 and 17 using the subtraction method

  1. Subtract \(71 - 17 = 54\). The result is not zero so we continue.
  2. Take all factors of 2 from \(54\). So 54 becomes 27.
  3. We repeat the subtraction step so \(27 - 17 = 10\). The result is not zero so we continue by taking 2 out of 10 to get 5.
  4. We subtract again, \(17 - 5 = 12\). Take the 2 factor out twice to get 3
  5. We subtract \(5 - 3 = 2\). Take the factor 2 out to get 1.
  6. We subtract \(3 - 1 = 2\), Take the factor 2 out to get 1.
  7. Finally \(1 - 1 = 0\) so. we stop.

So the greatest common of 17 and 71 is 1. The greatest common divisor of 68 and 142 is therefore \(2 \cdot 1 = 2\).


The Least Common Multiple

The least common multiple of two numbers \(a\) and \(b\) is defined to be the smallest multiple of \(a\) and \(b\). So this means it will be at most \(ab\). In fact,

$$ \begin{align*} lcm(a,b) = \frac{ab}{gcd(a,b)} \end{align*} $$

References