Section 5.2 Introduction to Number Theory
¶We have used the natural numbers to solve problems. This was the right set of numbers to work with in discrete mathematics because we always dealt with a whole number of things. The natural numbers have been a tool. Let's take a moment now to inspect that tool. What mathematical discoveries can we make about the natural numbers themselves?
This is the main question of number theory: a huge, ancient, complex, and above all, beautiful branch of mathematics. Historically, number theory was known as the Queen of Mathematics and was very much a branch of pure mathematics, studied for its own sake instead of as a means to understanding real world applications. This has changed in recent years however, as applications of number theory have been unearthed. Probably the most well known example of this is RSA cryptography, one of the methods used in encrypt data on the internet. It is number theory that makes this possible.
What sorts of questions belong to the realm of number theory? Here is a motivating example. Recall in our study of induction, we asked:
Which amounts of postage can be made exactly using just 5-cent and 8-cent stamps?
We were able to prove that any amount greater than 27 cents could be made. You might wonder what would happen if we changed the denomination of the stamps. What if we instead had 4- and 9-cent stamps? Would there be some amount after which all amounts would be possible? Well, again, we could replace two 4-cent stamps with a 9-cent stamp, or three 9-cent stamps with seven 4-cent stamps. In each case we can create one more cent of postage. Using this as the inductive case would allow us to prove that any amount of postage greater than 23 cents can be made.
What if we had 2-cent and 4-cent stamps. Here it looks less promising. If we take some number of 2-cent stamps and some number of 4-cent stamps, what can we say about the total? Could it ever be odd? Doesn't look like it.
Why does 5 and 8 work, 4 and 9 work, but 2 and 4 not work? What is it about these numbers? If I gave you a pair of numbers, could you tell me right away if they would work or not? We will answer these questions, and more, after first investigating some simpler properties of numbers themselves.
Subsection Divisibility
¶It is easy to add and multiply natural numbers. If we extend our focus to all integers, then subtraction is also easy (we need the negative numbers so we can subtract any number from any other number, even larger from smaller). Division is the first operation that presents a challenge. If we wanted to extend our set of numbers so any division would be possible (maybe excluding division by 0) we would need to look at the rational numbers (the set of all numbers which can be written as fractions). This would be going too far, so we will refuse this option.
In fact, it is a good thing that not every number can be divided by other numbers. This helps us understand the structure of the natural numbers and opens the door to many interesting questions and applications.
If given numbers \(a\) and \(b\text{,}\) it is possible that \(a \div b\) gives a whole number. In this case, we say that \(b\) divides \(a\text{,}\) in symbols, we write \(b \mid a\text{.}\) If this holds, then \(b\) is a divisor or factor of \(a\text{,}\) and \(a\) is a multiple of \(b\text{.}\) In other words, if \(b \mid a\text{,}\) then \(a = bk\) for some integer \(k\) (this is saying \(a\) is some multiple of \(b\)).
The Divisibility Relation.
Given integers \(m\) and \(n\text{,}\) we say “\(m\) divides \(n\)” and write
provided \(n \div m\) is an integer. Thus the following assertions mean the same thing:
- \(m \mid n\)
- \(n = mk\) for some integer \(k\)
- \(m\) is a factor (or divisor) of \(n\)
- \(n\) is a multiple of \(m\text{.}\)
Notice that \(m \mid n\) is a statement. It is either true or false. On the other hand, \(n \div m\) or \(n/m\) is some number. If we want to claim that \(n/m\) is not an integer, so \(m\) does not divide \(n\text{,}\) then we can write \(m \nmid n\text{.}\)
Example 5.2.1.
Decide whether each of the statements below are true or false.
- \(4 \mid 20\)
- \(20 \mid 4\)
- \(0 \mid 5\)
- \(5 \mid 0\)
- \(7 \mid 7\)
- \(1 \mid 37\)
- \(-3 \mid 12\)
- \(8 \mid 12\)
- \(1642 \mid 136299\)
True. 4 “goes into” 20 five times without remainder. In other words, \(20 \div 4 = 5\text{,}\) an integer. We could also justify this by saying that \(20\) is a multiple of 4: \(20 = 4\cdot 5\text{.}\)
False. While 20 is a multiple of 4, it is false that \(4\) is a multiple of 20.
False. \(5 \div 0\) is not even defined, let alone an integer.
True. In fact, \(x \mid 0\) is true for all \(x\text{.}\) This is because 0 is a multiple of every number: \(0 = x\cdot 0\text{.}\)
True. In fact, \(x \mid x\) is true for all \(x\text{.}\)
True. 1 divides every number (other than 0).
True. Negative numbers work just fine for the divisibility relation. Here \(12 = -3 \cdot 4\text{.}\) It is also true that \(3 \mid -12\) and that \(-3 \mid -12\text{.}\)
False. Both 8 and 12 are divisible by 4, but this does not mean that \(12\) is divisible by \(8\text{.}\)
False. See below.
This last example raises a question: how might one decide whether \(m \mid n\text{?}\) Of course, if you had a trusted calculator, you could ask it for the value of \(n \div m\text{.}\) If it spits out anything other than an integer, you know \(m \nmid n\text{.}\) This seems a little like cheating though: we don't have division, so should we really use division to check divisibility?
While we don't really know how to divide, we do know how to multiply. We might try multiplying \(m\) by larger and larger numbers until we get close to \(n\text{.}\) How close? Well, we want to be sure that if we multiply \(m\) by the next larger integer, we go over \(n\text{.}\)
For example, let's try this to decide whether \(1642 \mid 136299\text{.}\) Start finding multiples of 1642:
All of these are well less than 136299. I suppose we can jump ahead a bit:
Ah, so we need to look somewhere between 80 and 85. Try 83:
Is this the best we can do? How far are we from our desired 136299? If we subtract, we get \(136299 - 136286 = 13\text{.}\) So we know we cannot go up to 84, that will be too much. In other words, we have found that
Since \(13 \lt 1642\text{,}\) we can now safely say that \(1642 \nmid 136299\text{.}\)
It turns out that the process we went through above can be repeated for any pair of numbers. We can always write the number \(a\) as some multiple of the number \(b\) plus some remainder. We know this because we know about division with remainder from elementary school. This is just a way of saying it using multiplication. Due to the procedural nature that can be used to find the remainder, this fact is usually called the division algorithm:
The Division Algorithm.
Given any two integers \(a\) and \(b\text{,}\) we can always find an integer \(q\) such that
where \(r\) is an integer satisfying \(0 \le r \lt |b|\)
The idea is that we can always take a large enough multiple of \(b\) so that the remainder \(r\) is as small as possible. We do allow the possibility of \(r = 0\text{,}\) in which case we have \(b \mid a\text{.}\)
Subsection Remainder Classes
¶The division algorithm tells us that there are only \(b\) possible remainders when dividing by \(b\text{.}\) If we fix this divisor, we can group integers by the remainder. Each group is called a remainder class modulo \(b\) (or sometimes residue class).
Example 5.2.2.
Describe the remainder classes modulo \(5\text{.}\)
We want to classify numbers by what their remainder would be when divided by \(5\text{.}\) From the division algorithm, we know there will be exactly 5 remainder classes, because there are only 5 choices for what \(r\) could be (\(0 \le r \lt 5\)).
First consider \(r = 0\text{.}\) Here we are looking for all the numbers divisible by \(5\) since \(a = 5q+0\text{.}\) In other words, the multiples of 5. We get the infinite set
Notice we also include negative integers.
Next consider \(r = 1\text{.}\) Which integers, when divided by 5, have remainder 1? Well, certainly 1, does, as does 6, and 11. Negatives? Here we must be careful: \(-6\) does NOT have remainder 1. We can write \(-6 = -2\cdot 5 + 4\) or \(-6 = -1 \cdot 5 - 1\text{,}\) but only one of these is a “correct” instance of the division algorithm: \(r = 4\) since we need \(r\) to be non-negative. So in fact, to get \(r = 1\text{,}\) we would have \(-4\text{,}\) or \(-9\text{,}\) etc. Thus we get the remainder class
There are three more to go. The remainder classes for \(2\text{,}\) \(3\text{,}\) and \(4\) are, respectively
Note that in the example above, every integer is in exactly one remainder class. The technical way to say this is that the remainder classes modulo \(b\) form a partition of the integers. 1 It is possible to develop a mathematical theory of partitions, prove statements about all partitions in general and then apply those observations to our case here. The most important fact about partitions, is that it is possible to define an equivalence relation from a partition: this is a relationship between pairs of numbers which acts in all the important ways like the “equals” relationship. 2 Again, there is a mathematical theory of equivalence relations which applies in many more instances than the one we look at here.
All fun technical language aside, the idea is really simple. If two numbers belong to the same remainder class, then in some way, they are the same. That is, they are the same up to division by \(b\). In the case where \(b = 5\) above, the numbers \(8\) and \(23\text{,}\) while not the same number, are the same when it comes to dividing by 5, because both have remainder \(3\text{.}\)
It matters what the divisor is: \(8\) and \(23\) are the same up to division by \(5\text{,}\) but not up to division by \(7\text{,}\) since \(8\) has remainder of 1 when divided by 7 while 23 has a remainder of 2.
With all this in mind, let's introduce some notation. We want to say that \(8\) and 23 are basically the same, even though they are not equal. It would be wrong to say \(8 = 23\text{.}\) Instead, we write \(8 \equiv 23\text{.}\) But this is not always true. It works if we are thinking division by 5, so we need to denote that somehow. What we will actually write is this:
which is read, “8 is congruent to 23 modulo 5” (or just “mod 5”). Of course then we could observe that
Congruence Modulo \(n\).
We say \(a\) is congruent to \(b\) modulo \(n\), and write,
provided \(a\) and \(b\) have the same remainder when divided by \(n\text{.}\) In other words, provided \(a\) and \(b\) belong to the same remainder class modulo \(n\text{.}\)
Many books define congruence modulo \(n\) slightly differently. They say that \(a \equiv b \pmod{n}\) if and only if \(n \mid a-b\text{.}\) In other words, two numbers are congruent modulo \(n\text{,}\) if their difference is a multiple of \(n\text{.}\) So which definition is correct? Turns out, it doesn't matter: they are equivalent.
To see why, consider two numbers \(a\) and \(b\) which are congruent modulo \(n\text{.}\) Then \(a\) and \(b\) have the same remainder when divided by \(n\text{.}\) We have
Here the two \(r\)'s really are the same. Consider what we get when we take the difference of \(a\) and \(b\text{:}\)
So \(a-b\) is a multiple of \(n\text{,}\) or equivalently, \(n \mid a-b\text{.}\)
On the other hand, if we assume first that \(n \mid a-b\text{,}\) so \(a-b = kn\text{,}\) then consider what happens if we divide each term by \(n\text{.}\) Dividing \(a\) by \(n\) will leave some remainder, as will dividing \(b\) by \(n\text{.}\) However, dividing \(kn\) by \(n\) will leave 0 remainder. So the remainders on the left-hand side must cancel out. That is, the remainders must be the same.
Thus we have:
Congruence and Divisibility.
For any integers \(a\text{,}\) \(b\text{,}\) and \(n\text{,}\) we have
It will also be useful to switch back and forth between congruences and regular equations. The above fact helps with this. We know that \(a \equiv b \pmod{n}\) if and only if \(n \mid a-b\text{,}\) if and only if \(a-b = kn\) for some integer \(k\text{.}\) Rearranging that equation, we get \(a = b + kn\text{.}\) In other words, if \(a\) and \(b\) are congruent modulo \(n\text{,}\) then \(a\) is \(b\) more than some multiple of \(n\text{.}\) This conforms with our earlier observation that all the numbers in a particular remainder class are the same amount larger than the multiples of \(n\text{.}\)
Congruence and Equality.
For any integers \(a\text{,}\) \(b\text{,}\) and \(n\text{,}\) we have
Subsection Properties of Congruence
¶We said earlier that congruence modulo \(n\) behaves, in many important ways, the same way equality does. Specifically, we could prove that congruence modulo \(n\) is an equivalence relation, which would require checking the following three facts:
Congruence Modulo \(n\) is an Equivalence Relation.
Given any integers \(a\text{,}\) \(b\text{,}\) and \(c\text{,}\) and any positive integer \(n\text{,}\) the following hold:
- \(a \equiv a \pmod{n}\text{.}\)
If \(a \equiv b \pmod{n}\) then \(b \equiv a \pmod{n}\text{.}\)
If \(a \equiv b \pmod{n}\) and \(b \equiv c \pmod{n}\text{,}\) then \(a \equiv c \pmod{n}\text{.}\)
In other words, congruence modulo \(n\) is reflexive, symmetric, and transitive, so is an equivalence relation.
You should take a minute to convince yourself that each of the properties above actually hold of congruence. Try explaining each using both the remainder and divisibility definitions.
Next, consider how congruence behaves when doing basic arithmetic. We already know that if you subtract two congruent numbers, the result will be congruent to 0 (be a multiple of \(n\)). What if we add something congruent to 1 to something congruent to 2? Will we get something congruent to 3?
Congruence and Arithmetic.
Suppose \(a \equiv b \pmod{n}\) and \(c \equiv d \pmod{n}\text{.}\) Then the following hold:
- \(a+c \equiv b+d \pmod{n}\text{.}\)
- \(a-c \equiv b-d \pmod{n}\text{.}\)
- \(ac \equiv bd \pmod{n}\text{.}\)
The above facts might be written a little strangely, but the idea is simple. If we have a true congruence, and we add the same thing to both sides, the result is still a true congruence. This sounds like we are saying:
If \(a \equiv b \pmod{n}\) then \(a+c \equiv b+c \pmod{n}\text{.}\)
Of course this is true as well, it is the special case where \(c = d\text{.}\) But what we have works in more generality. Think of congruence as being “basically equal.” If we have two numbers which are basically equal, and we add basically the same thing to both sides, the result will be basically equal.
This seems reasonable. Is it really true? Let's prove the first fact:
Proof.
Suppose \(a \equiv b \pmod{n}\) and \(c \equiv d \pmod{n}\text{.}\) That means \(a = b + kn\) and \(c = d + jn\) for integers \(k\) and \(j\text{.}\) Add these equations:
But \(kn + jn = (k+j)n\text{,}\) which is just a multiple of \(n\text{.}\) So \(a+c = b+d + (j+k)n\text{,}\) or in other words, \(a+c \equiv b+d \pmod{n}\)
The other two facts can be proved in a similar way.
One of the important consequences of these facts about congruences, is that we can basically replace any number in a congruence with any other number it is congruent to. Here are some examples to see how (and why) that works:
Example 5.2.3.
Find the remainder of \(3491\) divided by \(9\text{.}\)
We could do long division, but there is another way. We want to find \(x\) such that \(x \equiv 3491 \pmod{9}\text{.}\) Now \(3491 = 3000 + 400 + 90 + 1\text{.}\) Of course \(90 \equiv 0 \pmod 9\text{,}\) so we can replace the 90 in the sum with 0. Why is this okay? We are actually subtracting the “same” thing from both sides:
Next, note that \(400 = 4 \cdot 100\text{,}\) and \(100 \equiv 1 \pmod 9\) (since \(9 \mid 99\)). So we can in fact replace the 400 with simply a 4. Again, we are appealing to our claim that we can replace congruent elements, but we are really appealing to property 3 about the arithmetic of congruence: we know \(100 \equiv 1 \pmod{9}\text{,}\) so if we multiply both sides by \(4\text{,}\) we get \(400 \equiv 4 \pmod 9\text{.}\)
Similarly, we can replace 3000 with 3, since \(1000 = 1 + 999 \equiv 1 \pmod 9\text{.}\) So our original congruence becomes
Therefore \(3491\) divided by 9 has remainder 8.
The above example should convince you that the well known divisibility test for 9 is true: the sum of the digits of a number is divisible by 9 if and only if the original number is divisible by 9. In fact, we now know something more: any number is congruent to the sum of its digits, modulo 9. 3 This works for 3 as well, but definitely not for any modulus in general.
Let's try another:
Example 5.2.4.
Find the remainder when \(3^{123}\) is divided by 7.
Of course, we are working with congruence because we want to find the smallest positive \(x\) such that \(x \equiv 3^{123} \pmod 7\text{.}\) Now first write \(3^{123} = (3^3)^{41}\text{.}\) We have:
since \(27 \equiv 6 \pmod 7\text{.}\) Notice further that \(6^2 = 36\) is congruent to 1 modulo 7. Thus we can simplify further:
But \(1^{20} = 1\text{,}\) so we are done:
In the above example, we are using the fact that if \(a \equiv b \pmod n\text{,}\) then \(a^p \equiv b^p \pmod n\text{.}\) This is just applying property 3 a bunch of times.
So far we have seen how to add, subtract and multiply with congruences. What about division? There is a reason we have waited to discuss it. It turns out that we cannot simply divide. In other words, even if \(ad \equiv bd \pmod n\text{,}\) we do not know that \(a \equiv b \pmod n\text{.}\) Consider, for example:
This is true. Now \(18\) and \(42\) are both divisible by 6. However,
While this doesn't work, note that \(3 \equiv 7 \pmod 4\text{.}\) We cannot divide \(8\) by 6, but we can divide 8 by the greatest common factor of \(8\) and \(6\text{.}\) Will this always happen?
Suppose \(ad \equiv bd \pmod n\text{.}\) In other words, we have \(ad = bd + kn\) for some integer \(k\text{.}\) Of course \(ad\) is divisible by \(d\text{,}\) as is \(bd\text{.}\) So \(kn\) must also be divisible by \(d\text{.}\) Now if \(n\) and \(d\) have no common factors (other than 1), then we must have \(d \mid k\text{.}\) But in general, if we try to divide \(kn\) by \(d\text{,}\) we don't know that we will get an integer multiple of \(n\text{.}\) Some of the \(n\) might get divided as well. To be safe, let's divide as much of \(n\) as we can. Take the largest factor of both \(d\) and \(n\text{,}\) and cancel that out from \(n\text{.}\) The rest of the factors of \(d\) will come from \(k\text{,}\) no problem.
We will call the largest factor of both \(d\) and \(n\) the \(\gcd(d,n)\text{,}\) for greatest common divisor. In our example above, \(\gcd(6,8) = 2\) since the greatest divisor common to 6 and 8 is 2.
Congruence and Division.
Suppose \(ad \equiv bd \pmod n\text{.}\) Then \(a \equiv b \pmod{\frac{n}{\gcd(d,n)}}\text{.}\)
If \(d\) and \(n\) have no common factors then \(\gcd(d,n) = 1\text{,}\) so \(a \equiv b \pmod n\text{.}\)
Example 5.2.5.
Simplify the following congruences using division: (a) \(24 \equiv 39 \pmod 5\) and (b) \(24 \equiv 39 \pmod{15}\text{.}\)
(a) Both \(24\) and \(39\) are divisible by \(3\text{,}\) and \(3\) and \(5\) have no common factors, so we get
(b) Again, we can divide by 3. However, doing so blindly gives us \(8 \equiv 13 \pmod{15}\) which is no longer true. Instead, we must also divide the modulus 15 by the greatest common factor of \(3\) and \(15\text{,}\) which is \(3\text{.}\) Again we get
Subsection Solving Congruences
¶Now that we have some algebraic rules to govern congruence relations, we can attempt to solve for an unknown in a congruence. For example, is there a value of \(x\) that satisfies,
and if so, what is it?
In this example, since the modulus is small, we could simply try every possible value for \(x\text{.}\) There are really only 5 to consider, since any integer that satisfied the congruence could be replaced with any other integer it was congruent to modulo 5. Here, when \(x = 4\) we get \(3x + 2 = 14\) which is indeed congruent to 4 modulo 5. This means that \(x = 9\) and \(x = 14\) and \(x = 19\) and so on will each also be a solution because as we saw above, replacing any number in a congruence with a congruent number does not change the truth of the congruence.
So in this example, simply compute \(3x + 2\) for values of \(x \in \{0,1,2,3,4\}\text{.}\) This gives 2, 5, 8, 11, and 14 respectively, for which only 14 is congruent to 4.
Let's also see how you could solve this using our rules for the algebra of congruences. Such an approach would be much simpler than the trial and error tactic if the modulus was larger. First, we know we can subtract 2 from both sides:
Then to divide both sides by 3, we first add 0 to both sides. Of course, on the right-hand side, we want that 0 to be a 10 (yes, \(10\) really is 0 since they are congruent modulo 5). This gives,
Now divide both sides by 3. Since \(\gcd(3,5) = 1\text{,}\) we do not need to change the modulus:
Notice that this in fact gives the general solution: not only can \(x = 4\text{,}\) but \(x\) can be any number which is congruent to 4. We can leave it like this, or write “\(x = 4 + 5k\) for any integer \(k\text{.}\)”
Example 5.2.6.
Solve the following congruences for \(x\text{.}\)
- \(7x \equiv 12 \pmod{13}\text{.}\)
- \(84x - 38 \equiv 79 \pmod{15}\text{.}\)
- \(20x \equiv 23 \pmod{14}\text{.}\)
-
All we need to do here is divide both sides by 7. We add 13 to the right-hand side repeatedly until we get a multiple of 7 (adding 13 is the same as adding 0, so this is legal). We get \(25\text{,}\) \(38\text{,}\) \(51\text{,}\) \(64\text{,}\) \(77\) – got it. So we have:
\begin{equation*} \begin{aligned}7x \amp \equiv 12 \pmod{13} \\ 7x \amp \equiv 77 \pmod{13} \\ x \amp \equiv 11 \pmod{13}. \end{aligned} \end{equation*} -
Here, since we have numbers larger than the modulus, we can reduce them prior to applying any algebra. We have \(84 \equiv 9\text{,}\) \(38 \equiv 8\) and \(79 \equiv 4\text{.}\) Thus,
\begin{equation*} \begin{aligned}84x - 38 \amp \equiv 79 \pmod{15} \\ 9x - 8 \amp \equiv 4 \pmod{15} \\ 9x \amp \equiv 12 \pmod{15} \\ 9x \amp \equiv 72 \pmod{15}. \end{aligned} \end{equation*}We got the 72 by adding \(0 \equiv 60 \pmod{15}\) to both sides of the congruence. Now divide both sides by 9. However, since \(\gcd(9, 15) = 3\text{,}\) we must divide the modulus by 3 as well:
\begin{equation*} x \equiv 8 \pmod 5\text{.} \end{equation*}So the solutions are those values which are congruent to 8, or equivalently 3, modulo 5. This means that in some sense there are 3 solutions modulo 15: 3, 8, and 13. We can write the solution:
\begin{equation*} x \equiv 3 \pmod{15}; ~~ x \equiv 8 \pmod{15}; ~~x \equiv 13 \pmod{15}\text{.} \end{equation*} -
First, reduce modulo 14:
\begin{equation*} 20x \equiv 23 \pmod{14} \end{equation*}\begin{equation*} 6x \equiv 9 \pmod{14}\text{.} \end{equation*}We could now divide both sides by 3, or try to increase 9 by a multiple of 14 to get a multiple of 6. If we divide by 3, we get,
\begin{equation*} 2x \equiv 3 \pmod{14}\text{.} \end{equation*}Now try adding multiples of 14 to 3, in hopes of getting a number we can divide by 2. This will not work! Every time we add 14 to the right side, the result will still be odd. We will never get an even number, so we will never be able to divide by 2. Thus there are no solutions to the congruence.
The last congruence above illustrates the way in which congruences might not have solutions. We could have seen this immediately in fact. Look at the original congruence:
If we write this as an equation, we get
or equivalently \(20x - 14k = 23\text{.}\) We can easily see there will be no solution to this equation in integers. The left-hand side will always be even, but the right-hand side is odd. A similar problem would occur if the right-hand side was divisible by any number the left-hand side was not.
So in general, given the congruence
if \(a\) and \(n\) are divisible by a number which \(b\) is not divisible by, then there will be no solutions. In fact, we really only need to check one divisor of \(a\) and \(n\text{:}\) the greatest common divisor. Thus, a more compact way to say this is:
Congruences with no solutions.
If \(\gcd(a,n) \nmid b\text{,}\) then \(ax \equiv b \pmod{n}\) has no solutions.
Subsection Solving Linear Diophantine Equations
¶Discrete math deals with whole numbers of things. So when we want to solve equations, we usually are looking for integer solutions. Equations which are intended to only have integer solutions were first studied by in the third century by the Greek mathematician Diophantus of Alexandria, and as such are called Diophantine equations. Probably the most famous example of a Diophantine equation is \(a^2 + b^2 = c^2\text{.}\) The integer solutions to this equation are called Pythagorean triples. In general, solving Diophantine equations is hard (in fact, there is provably no general algorithm for deciding whether a Diophantine equation has a solution, a result known as Matiyasevich's Theorem). We will restrict our focus to linear Diophantine equations, which are considerably easier to work with.
Diophantine Equations.
An equation in two or more variables is called a Diophantine equation if only integers solutions are of interest. A linear Diophantine equation takes the form \(a_1x_1 + a_2x_x + \cdots + a_nx_n = b\) for constants \(a_1,\ldots, a_n, b\text{.}\)
A solution to a Diophantine equation is a solution to the equation consisting only of integers.
We have the tools we need to solve linear Diophantine equations. We will consider, as a main example, the equation
The general strategy will be to convert the equation to a congruence, then solve that congruence. 4 This is certainly not the only way to proceed. A more common technique would be to apply the Euclidean algorithm. Our way can be a little faster, and is presented here primarily for variety. Let's work this particular example to see how this might go.
First, check if perhaps there are no solutions because a divisor of \(51\) and \(87\) is not a divisor of \(123\text{.}\) Really, we just need to check whether \(\gcd(51, 87) \mid 123\text{.}\) This greatest common divisor is 3, and yes \(3 \mid 123\text{.}\) At this point, we might as well factor out this greatest common divisor. So instead, we will solve:
Now observe that if there are going to be solutions, then for those values of \(x\) and \(y\text{,}\) the two sides of the equation must have the same remainder as each other, no matter what we divide by. In particular, if we divide both sides by 17, we must get the same remainder. Thus we can safely write
We choose 17 because \(17x\) will have remainder 0. This will allow us to reduce the congruence to just one variable. We could have also moved to a congruence modulo 29, although there is usually a good reason to select the smaller choice, as this will allow us to reduce the other coefficient. In our case, we reduce the congruence as follows:
Now at this point we know \(y = 2 + 17k\) will work for any integer \(k\text{.}\) If we haven't made a mistake, we should be able to plug this back into our original Diophantine equation to find \(x\text{:}\)
We have now found all solutions to the Diophantine equation. For each \(k\text{,}\) \(x = -1-29k\) and \(y = 2 + 17k\) will satisfy the equation. We could check this for a few cases. If \(k = 0\text{,}\) the solution is \((-1,2)\text{,}\) and yes, \(-17 + 2\cdot 29 = 41\text{.}\) If \(k = 3\text{,}\) the solution is \((-88, 53)\text{.}\) If \(k = -2\text{,}\) we get \((57, -32)\text{.}\)
To summarize this process, to solve \(ax + by = c\text{,}\) we,
Divide both sides of the equation by \(\gcd(a,b)\) (if this does not leave the right-hand side as an integer, there are no solutions). Let's assume that \(ax + by = c\) has already been reduced in this way.
-
Pick the smaller of \(a\) and \(b\) (here, assume it is \(b\)), and convert to a congruence modulo \(b\text{:}\)
\begin{equation*} ax + by \equiv c \pmod{b}\text{.} \end{equation*}This will reduce to a congruence with one variable, \(x\text{:}\)
\begin{equation*} ax \equiv c \pmod{b}\text{.} \end{equation*} -
Solve the congruence as we did in the previous section. Write your solution as an equation, such as,
\begin{equation*} x = n + kb\text{.} \end{equation*} Plug this into the original Diophantine equation, and solve for \(y\text{.}\)
If we want to know solutions in a particular range (for example, \(0 \le x, y \le 20\)), pick different values of \(k\) until you have all required solutions.
Here is another example:
Example 5.2.7.
How can you make $6.37 using just 5-cent and 8-cent stamps? What is the smallest and largest number of stamps you could use?
First, we need a Diophantine equation. We will work in numbers of cents. Let \(x\) be the number of \(5\)-cent stamps, and \(y\) be the number of 8-cent stamps. We have:
Convert to a congruence and solve:
Thus \(y = 4 + 5k\text{.}\) Then \(5x + 8(4+5k) = 637\text{,}\) so \(x = 121 - 8k\text{.}\)
This says that one way to make $6.37 is to take 121 of the 5-cent stamps and 4 of the 8-cent stamps. To find the smallest and largest number of stamps, try different values of \(k\text{.}\)
\(k\) | \((x,y)\) | Stamps |
-1 | (129, -1) | not possible |
0 | (121, 4) | 125 |
1 | (113, 9) | 122 |
2 | (105, 13) | 119 |
\vdots | \vdots | \vdots |
This is no surprise. Having the most stamps means we have as many 5-cent stamps as possible, and to get the smallest number of stamps would require have the least number of 5-cent stamps. To minimize the number of 5-cent stamps, we want to pick \(k\) so that \(121-8k\) is as small as possible (but still positive). When \(k = 15\text{,}\) we have \(x = 1\) and \(y = 79\text{.}\)
Therefore, to make $6.37, you can us as few as 80 stamps (1 5-cent stamp and 79 8-cent stamps) or as many as 125 stamps (121 5-cent stamps and 4 8-cent stamps).
Using this method, as long as you can solve linear congruences in one variable, you can solve linear Diophantine equations of two variables. There are times though that solving the linear congruence is a lot of work. For example, suppose you need to solve,
You could keep adding 51 to the right side until you get a multiple of 13: You would get 57, 108, 159, 210, 261, 312, and 312 is the first of these that is divisible by 13. This works, but is really too much work. Instead we could convert back to a Diophantine equation:
Now solve this like we have in this section. Write it as a congruence modulo 13:
so \(k = 6 + 13j\text{.}\) Now go back and figure out \(x\text{:}\)
Of course you could do this switching back and forth between congruences and Diophantine equations as many times as you like. If you only used this technique, you would essentially replicate the Euclidean algorithm, a more standard way to solve Diophantine equations.
Exercises Exercises
¶1.
Suppose \(a\text{,}\) \(b\text{,}\) and \(c\) are integers. Prove that if \(a \mid b\text{,}\) then \(a \mid bc\text{.}\)
Proof.
Suppose \(a \mid b\text{.}\) Then \(b\) is a multiple of \(a\text{,}\) or in other words, \(b = ak\) for some \(k\text{.}\) But then \(bc = akc\text{,}\) and since \(kc\) is an integer, this says \(bc\) is a multiple of \(a\text{.}\) In other words, \(a \mid bc\text{.}\)
2.
Suppose \(a\text{,}\) \(b\text{,}\) and \(c\) are integers. Prove that if \(a \mid b\) and \(a \mid c\) then \(a \mid b+c\) and \(a \mid b-c\text{.}\)
3.
Write out the remainder classes for \(n = 4\text{.}\)
\(\{\ldots, -8, -4, 0, 4, 8, 12, \ldots\}\text{,}\) \(\{\ldots, -7, -3, 1, 5, 9, 13, \ldots\}\text{,}\)
\(\{\ldots, -6, -2, 2, 6, 10, 14, \ldots\}\text{,}\) and \(\{\ldots, -5, -1, 3, 7, 11, 15, \ldots\}\text{.}\)
4.
What is the largest \(n\) such that \(16\) and \(25\) are in the same remainder class modulo \(n\text{?}\) Write out the remainder class they both belong to and give an example of a number more than 100 in that class.
5.
Let \(a\text{,}\) \(b\text{,}\) \(c\text{,}\) and \(n\) be integers. Prove that if \(a \equiv b \pmod{n}\) and \(c \equiv d \pmod{n}\text{,}\) then \(a-c \equiv b-d \pmod{n}\text{.}\)
Proof.
Assume \(a \equiv b \pmod n\) and \(c \equiv d \pmod n\text{.}\) This means \(a = b + kn\) and \(c = d + jn\) for some integers \(k\) and \(j\text{.}\) Consider \(a-c\text{.}\) We have:
In other words, \(a-c\) is \(b-d\) more than some multiple of \(n\text{,}\) so \(a-c \equiv b-d \pmod n\text{.}\)
6.
Find the remainder of \(3^{456}\) when divided by
2.
5.
7.
9.
- \(3^{456} \equiv 1^{456} = 1 \pmod 2\text{.}\)
- \(3^{456} = 9^{228} \equiv (-1)^{228} = 1 \pmod{5}\text{.}\)
- \(3^{456} = 9^{228} \equiv 2^{228} = 8^{76} \equiv 1^{76} = 1 \pmod 7\text{.}\)
- \(3^{456} = 9^{228} \equiv 0^{228} = 0 \pmod{9}\text{.}\)
7.
Repeat the previous exercise, this time dividing \(2^{2019}\text{.}\)
8.
Determine which of the following congruences have solutions, and find any solutions (between 0 and the modulus) by trial and error.
- \(4x \equiv 5 \pmod 6\text{.}\)
- \(6x \equiv 3 \pmod 9\text{.}\)
- \(x^2 \equiv 2 \pmod 4\text{.}\)
For all of these, just plug in all integers between 0 and the modulus to see which, if any, work.
No solutions.
- \(x = 2\text{,}\) \(x = 5\text{,}\) \(x = 8\text{.}\)
No solutions.
9.
Determine which of the following congruences have solutions, and find any solutions (between 0 and the modulus) by trial and error.
- \(4x \equiv 5 \pmod 7\text{.}\)
- \(6x \equiv 4 \pmod 9\text{.}\)
- \(x^2 \equiv 2 \pmod 7\text{.}\)
10.
Solve the following congruence \(5x + 8 \equiv 11 \pmod{22}\text{.}\) That is, describe the general solution.
\(x = 5+22k\) for \(k \in \Z\text{.}\)
11.
Solve the congruence: \(6x \equiv 4 \pmod{10}\text{.}\)
12.
Solve the congruence: \(4x \equiv 24 \pmod{30}\text{.}\)
\(x = 6 + 15k\) for \(k \in \Z\text{.}\)
13.
Solve the congruence: \(341x \equiv 2941 \pmod{9}\text{.}\)
First reduce each number modulo 9, which can be done by adding up the digits of the numbers.
14.
I'm thinking of a number. If you multiply my number by 7, add 5, and divide the result by 11, you will be left with a remainder of 2. What remainder would you get if you divided my original number by 11?
We must solve \(7x + 5 \equiv 2 \pmod{11}\text{.}\) This gives \(x \equiv 9 \pmod{11}\text{.}\) In general, \(x = 9 + 11k\text{,}\) but when you divide any such \(x\) by 11, the remainder will be 9.
15.
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions).
Divide through by 2: \(3x + 5y = 16\text{.}\) Convert to a congruence, modulo 3: \(5y \equiv 16 \pmod 3\text{,}\) which reduces to \(2y \equiv 1 \pmod 3\text{.}\) So \(y \equiv 2 \pmod 3\) or \(y = 2 + 3k\text{.}\) Plug this back into \(3x + 5y = 16\) and solve for \(x\text{,}\) to get \(x = 2-5k\text{.}\) So the general solution is \(x = 2-5k\) and \(y = 2+3k\) for \(k \in \Z\text{.}\)
16.
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions).
17.
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions).
18.
You have a 13 oz. bottle and a 20 oz. bottle, with which you wish to measure exactly 2 oz. However, you have a limited supply of water. If any water enters either bottle and then gets dumped out, it is gone forever. What is the least amount of water you can start with and still complete the task?
Solve the Diophantine equation \(13x + 20 y = 2\) (why?). Then consider which value of \(k\) (the parameter in the solution) is optimal.