maths.free › Discrete Math & Logic › 7. Additional Topics › Introduction to Number Theory
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.
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 to 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.
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 that 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\), it is possible that \(a \div b\) gives a whole number. In this case, we say that \(b\) divides \(a\); in symbols, we write \(b \mid a\). If this holds, then \(b\) is a divisor or factor of \(a\), and \(a\) is a multiple of \(b\). In other words, if \(b \mid a\), then \(a = bk\) for some integer \(k\) (this is saying \(a\) is some multiple of \(b\)).
Given integers \(m\) and \(n\), we say \(m\) divides \(n\) and write \[m \mid n\] provided \(n \div m\) is an integer. Thus the following assertions mean the same thing:
- \(m \mid n\)
- \(n = mk\)\(k\)
- \(m\)\(n\)
- \(n\)\(m\)
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\), then we can write \(m \nmid n\).
This last example raises a question: How might one decide whether \(m \mid n\)? Of course, if you had a trusted calculator, you could ask it for the value of \(n \div m\). If it spits out anything other than an integer, you know \(m \nmid n\). 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\). How close? Well, we want to be sure that if we multiply \(m\) by the next larger integer, we go over \(n\).
For example, let's try this to decide whether \(1642 \mid 136299\). Start finding multiples of 1642: \[1642 \cdot 2 = 3284 \qquad 1642 \cdot 3 = 4926 \qquad 1642\cdot 4 = 6568 \qquad \cdots\].
Condensed — the full section is in Levin, Discrete Mathematics: An Open Introduction.
Remainder Classes
The division algorithm tells us that there are only \(b\) possible remainders when dividing by \(b\). 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
Describe the remainder classes modulo \(5\).
Solution
We want to classify numbers by what their remainder would be when divided by \(5\). 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\). Here we are looking for all the numbers divisible by \(5\) since \(a = 5q+0\). In other words, the multiples of 5. We get the infinite set \[\{\ldots, -15, -10, -5, 0, 5, 10, 15, 20, \ldots\}\].
Notice we also include negative integers.
Next consider \(r = 1\). 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\), 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\), we would have \(-4\), or \(-9\), etc. Thus we get the remainder class \[\{\ldots, -14, -9, -4, 1, 6, 11, 16, 21, \ldots\}\].
There are three more to go. The remainder classes for \(2\), \(3\), and \(4\) are, respectively \[\{\ldots, -13, -8, -3, 2, 7, 12, 17, 22,\ldots\}\] \[\{\ldots, -12, -7, -2, 3, 8, 13, 18, 23, \ldots\}\] \[\{\ldots, -11, -6, -1, 4, 9, 14, 19, 24, \ldots\}\].
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. 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. Again, there is a mathematical theory of equivalence relations which applies in many more instances than the one we look at here. See .
Condensed — the full section is in Levin, Discrete Mathematics: An Open Introduction.
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:
Given any integers \(a\), \(b\), and \(c\), and any positive integer \(n\), the following hold:
- \(a \equiv a \pmod{n}\)
If \(a \equiv b \pmod{n}\) then \(b \equiv a \pmod{n}\).
If \(a \equiv b \pmod{n}\) and \(b \equiv c \pmod{n}\), then \(a \equiv c \pmod{n}\).
In other words, congruence modulo \(n\) is reflexive, symmetric, and transitive, and so is an equivalence relation.
You should take a minute to convince yourself that each of the properties above actually holds for 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?
Suppose \(a \equiv b \pmod{n}\) and \(c \equiv d \pmod{n}\). Then the following hold:
- \(a+c \equiv b+d \pmod{n}\)
- \(a-c \equiv b-d \pmod{n}\)
- \(ac \equiv bd \pmod{n}\)
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}\).
Of course this is true as well; it is the special case where \(c = d\). But what we have works in more generality. Think of congruence as being basically equal. If we have two numbers that 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}\). That means \(a = b + kn\) and \(c = d + jn\) for integers \(k\) and \(j\). Add these equations: \[a+c = b+d + kn + jn\].
But \(kn + jn = (k+j)n\), which is just a multiple of \(n\). So \(a+c = b+d + (j+k)n\), or in other words, \(a+c \equiv b+d \pmod{n}\).
The other two facts can be proved in a similar way.
Condensed — the full section is in Levin, Discrete Mathematics: An Open Introduction.
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, \[3x + 2 \equiv 4 \pmod{5}\], and if so, what is it?
In this example, since the modulus is small, we could simply try every possible value for \(x\). 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\}\). 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: \[3x \equiv 2 \pmod{5}\].
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, \[3x \equiv 12 \pmod{5}\].
Now divide both sides by 3. Since \(\gcd(3,5) = 1\), we do not need to change the modulus: \[x \equiv 4 \pmod{5}\].
Notice that this in fact gives the general solution: Not only can \(x = 4\), 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\).
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: \[20x \equiv 23 \pmod{14}\].
If \(\gcd(a,n) \nmid b\), then \(ax \equiv b \pmod{n}\) has no solutions.
Condensed — the full section is in Levin, Discrete Mathematics: An Open Introduction.
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 that 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\). 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.
An equation in two or more variables is called a Diophantine equation if only integer solutions are of interest. A linear Diophantine equation takes the form \(a_1x_1 + a_2x_2 + \cdots + a_nx_n = b\) for constants \(a_1,\ldots, a_n, b\).
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 \[51x + 87y = 123\].
The general strategy will be to convert the equation to a congruence, and then solve that congruence. 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 through 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\). Really, we just need to check whether \(\gcd(51, 87) \mid 123\). This greatest common divisor is 3, and yes \(3 \mid 123\). At this point, we might as well factor out this greatest common divisor. So instead, we will solve: \[17x + 29y = 41\].
Now observe that if there are going to be solutions, then for those values of \(x\) and \(y\), 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 \[17x + 29y \equiv 41 \pmod{17}\].
Condensed — the full section is in Levin, Discrete Mathematics: An Open Introduction.
Practice (18)
Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.
-
Suppose \(a\), \(b\), and \(c\) are integers. Prove that if \(a \mid b\), then \(a \mid bc\).
Afslør svaret
Proof
Suppose \(a \mid b\). Then \(b\) is a multiple of \(a\), or in other words, \(b = ak\) for some \(k\). But then \(bc = akc\), and since \(kc\) is an integer, this says \(bc\) is a multiple of \(a\). In other words, \(a \mid bc\).
-
Suppose \(a\), \(b\), and \(c\) are integers. Prove that if \(a \mid b\) and \(a \mid c\) then \(a \mid b+c\) and \(a \mid b-c\).
-
Write out the remainder classes for \(n = 4\).
Afslør svaret
\(\{\ldots, -8, -4, 0, 4, 8, 12, \ldots\}\), \(\{\ldots, -7, -3, 1, 5, 9, 13, \ldots\}\),
\(\{\ldots, -6, -2, 2, 6, 10, 14, \ldots\}\), and \(\{\ldots, -5, -1, 3, 7, 11, 15, \ldots\}\).
-
What is the largest \(n\) such that \(16\) and \(25\) are in the same remainder class modulo \(n\)? Write out the remainder class they both belong to and give an example of a number more than 100 in that class.
-
Let \(a\), \(b\), \(c\), and \(n\) be integers. Prove that if \(a \equiv b \pmod{n}\) and \(c \equiv d \pmod{n}\), then \(a-c \equiv b-d \pmod{n}\).
Afslør svaret
Proof
Assume \(a \equiv b \pmod n\) and \(c \equiv d \pmod n\). This means \(a = b + kn\) and \(c = d + jn\) for some integers \(k\) and \(j\). Consider \(a-c\). We have: \[a-c = b+kn - (d+jn) = b-d + (k-j)n\].
In other words, \(a-c\) is \(b-d\) more than some multiple of \(n\), so \(a-c \equiv b-d \pmod n\).
-
Find the remainder of \(3^{456}\) when divided by
2.
5.
7.
9.
Afslør svaret
- \(3^{456} \equiv 1^{456} = 1 \pmod 2\)
- \(3^{456} = 9^{228} \equiv (-1)^{228} = 1 \pmod{5}\)
- \(3^{456} = 9^{228} \equiv 2^{228} = 8^{76} \equiv 1^{76} = 1 \pmod 7\)
- \(3^{456} = 9^{228} \equiv 0^{228} = 0 \pmod{9}\)
-
Repeat the previous exercise, this time dividing \(2^{2019}\).
-
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\)
- \(6x \equiv 3 \pmod 9\)
- \(x^2 \equiv 2 \pmod 4\)
Afslør svaret
For all of these, just plug in all integers between 0 and the modulus to see which, if any, work.
No solutions.
- \(x = 2\)\(x = 5\)\(x = 8\)
No solutions.
-
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\)
- \(6x \equiv 4 \pmod 9\)
- \(x^2 \equiv 2 \pmod 7\)
-
Solve the congruence: \(5x + 8 \equiv 11 \pmod{22}\). That is, describe the general solution.
Afslør svaret
\(x = 5+22k\) for \(k \in \Z\).
-
Solve the congruence: \(6x \equiv 4 \pmod{10}\).
-
Solve the congruence: \(4x \equiv 24 \pmod{30}\).
Afslør svaret
\(x = 6 + 15k\) for \(k \in \Z\).
-
Solve the congruence: \(341x \equiv 2941 \pmod{9}\).
Afslør svaret
Hint:
First reduce each number modulo 9, which can be done by adding up the digits of the numbers.
-
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?
Afslør svaret
We must solve \(7x + 5 \equiv 2 \pmod{11}\). This gives \(x \equiv 9 \pmod{11}\). In general, \(x = 9 + 11k\), but when you divide any such \(x\) by 11, the remainder will be 9.
-
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions). \[6x + 10y = 32\].
Afslør svaret
Divide through by 2: \(3x + 5y = 16\). Convert to a congruence, modulo 3: \(5y \equiv 16 \pmod 3\), which reduces to \(2y \equiv 1 \pmod 3\). So \(y \equiv 2 \pmod 3\) or \(y = 2 + 3k\). Plug this back into \(3x + 5y = 16\), and solve for \(x\), to get \(x = 2-5k\). So the general solution is \(x = 2-5k\) and \(y = 2+3k\) for \(k \in \Z\).
-
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions). \[17x + 8y = 31\].
-
Solve the following linear Diophantine equation, using modular arithmetic (describe the general solutions). \[35x + 47y = 1\].
-
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?
Afslør svaret
Hint:
Solve the Diophantine equation \(13x + 20 y = 2\) (why?). Then consider which value of \(k\) (the parameter in the solution) is optimal.
Symbols used here
n divides a − b; a and b have the same remainder.
b is a multiple of a; the largest number dividing both.
x belongs to A; every element of A is in B.
Both signs at once: x = 3 ± 2 means 5 and 1.
Inequalities that allow equality; < and > exclude it.
n × (n−1) × … × 1; the number of orderings of n things. 0! = 1.
Number of k-element subsets of n things: n!/(k!(n−k)!).
Add a_k for k = 1 up to n.
In either; in both; in A but not B.
The set with no elements; the number of elements of A.
Quantifiers: every x; at least one x.
Logical connectives.
Marks the point where the statement has been established.
Grows no faster than n² (up to a constant), for large n.
What is left after dividing a by n.
Questions people ask
What makes mathematics "discrete"?
It deals with separate, countable objects — integers, graphs, statements — rather than continuous quantities. No limits, no infinitesimals; instead induction, counting and logic.
How does a proof by induction work?
Show the statement for the first case, then show that whenever it holds for n it holds for n + 1. Like dominoes: the first falls, and each knocks over the next.
Prøv din egen
Parts of this page are adapted from Levin, Discrete Mathematics: An Open Introduction (CC BY-SA 4.0). Condensed and re-explained here; errors are ours.
Mere i Discrete Math & Logic
Truth tablesSums and inductionProof by inductionAlgorithms and growth of functions