High School Mathematics Extensions/Primes/Full
|Problems & Projects|
|Problem Set Solutions|
A prime number (or prime for short) is a natural number that has exactly two divisors: itself and the number 1. Because 1 only has a single divisor, itself, we do not consider it to be a prime number. So, 2 is the first prime, 3 is the next prime, but 4 is not a prime because 4 divided by 2 equals 2 without a remainder. We've proved 4 has three divisors: 1, 2, and 4. Numbers with more than two divisors are called composite numbers.
The first 20 primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, and 71.
Primes are an endless source of fascination for mathematicians. Some of the problems concerning primes are so difficult that even decades of work by some of the most brilliant mathematicians have failed to solve them. One such problem is Goldbach's conjecture, which proposes that all even numbers greater than 3 can be expressed as the sum of two primes. No one has been able to prove it true or false.
This chapter will introduce some of the elementary properties of primes and their connection to an area of mathematics called modular arithmetics.
Geometric meaning of primes
Given 12 pieces of square floor tiles, can we assemble them into a rectangular shape in more than one way? Of course we can, this is due to the fact that
We do not distinguish between 2×6 and 6×2 because they are essentially equivalent arrangements.
But what about the number 7? Can you arrange 7 square floor tiles into rectangular shapes in more than one way? The answer is no, because 7 is a prime number.
Fundamental Theorem of Arithmetic
A theorem is a non-obvious mathematical fact. A theorem must be proven; a proposition that is generally believed to be true, but without a proof, is called a conjecture or a hypothesis.
With those definitions out of the way the fundamental theorem of arithmetic simply states that:
- Any natural number (except for 1) can be expressed as the product of primes in one and only one way.
Rearranging the multiplication order is not considered a different representation of the number, so there is no other way of expressing 12 as the product of primes.
A few more examples
It can be easily seen that a composite number has more than one prime factor (counting recurring prime factors multiple times).
- Bearing in mind the definition of the fundamental theorem of arithmetic, why isn't the number 1 considered a prime?
We know from the fundamental theorem of arithmetic that any integer can be expressed as the product of primes. The million dollar question is: given a number x, is there an easy way to find all prime factors of x?
If x is a small number then it is easy. For example 90 = 2 × 3 × 3 × 5. But what if x is large? For example x = 4539? Most people can't factorize 4539 into primes in their heads. But can a computer do it? Yes, the computer can factorize 4539 fairly quickly. We have 4539 = 3 × 17 × 89.
Since computers are very good at doing arithmetic, we can work out all the factors of x by simply instructing the computer to divide x by 2 then 3 then 5 then 7 ... and so on.
So there is an easy way to factorize a number into prime factors. Just apply the method described above. However, that method is too slow for large numbers: trying to factorize a number with thousands of digits would take more time than the current age of the universe. But is there a fast way? Or more precisely, is there an efficient way? There may be, but no one has found one yet. Some of the most widely used encryption schemes today (such as RSA) make use of the fact that we can't factorize large numbers into prime factors quickly. If such a method is found, a lot of internet transactions will be rendered unsafe.
Consider the following three examples of the dividing method in action.
- not a whole number, so 2 is not a factor of 21
- hence 3 and 7 are the factors of 21.
- x = 153
- x / 2 = 76.5 hence 2 is not a factor of 153
- x / 3 = 51 hence 3 and 51 are factors of 153
- 51 / 3 = 17 hence 3 and 17 are factors of 153
It is clear that 3, 9, 17 and 51 are the factors of 153. The prime factors of 153 are 3, 3 and 17 (3×3×17 = 153)
- 2057 / 2 = 1028.5
- 2057 / 11 = 187
- 187 / 11 = 17
- hence 11, 11 and 17 are the prime factors of 2057.
Factor the following numbers:
- 2187 Give up if it takes too long. There is a quick way.
Fun Fact -- Is this prime?
Interestingly, there is an efficient way of determining whether a number is prime with 100% accuracy with the help of a computer.
2, 5 and 3
The primes 2, 5, and 3 hold a special place in factorization. Firstly, all even numbers have 2 as one of their prime factors. Secondly, all numbers whose last digit is 0 or 5 can be divided wholly by 5.
The third case, where 3 is a prime factor, is the focus of this section. The underlying question is: is there a simple way to decide whether a number has 3 as one of its prime factors?
Theorem - Divisibility by 3
A number is divisible by 3 if and only if the sum of its digits is divisible by 3
For example, 272 is not divisible by 3, because 2 + 7 + 2 = 11, which is not divisible by 3.
945 is divisible by 3, because 9 + 4 + 5 = 18. And 18 is divisible by 3. In fact 945 / 3 = 315
Is 123456789 divisible by 3?
- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = (1 + 9) × 9 / 2 = 45
- 4 + 5 = 9
Nine is divisible by 3, therefore 45 is divisible by 3, therefore 123456789 is divisible by 3!
The beauty of the theorem lies in its recursive nature. A number is divisible by 3 if and only if the sum of its digits is divisible by 3. How do we know whether the sum of its digits is divisible by 3? Apply the theorem again!
info -- Recursion
A prominent computer scientist once said "To iterate is human, to recurse, divine." But what does it mean to recurse? Before that, what is to iterate?
"To iterate" simply means doing the same thing over and over again, and computers are very good at that. An example of iteration in mathematics is the exponential operation, e.g. xn means doing x times x times x times x...n times. That is an example of iteration.
Thinking about iteration economically (in terms of mental resources), by defining a problem in terms of itself, is "to recurse". To recursively represent xn, we write:
- if n equals 0.
- if n > 0
What is 99? It is 9 times 9 8. But, 98 is 9 times 97. Repeating this way is an example of recursion.
2. Show that the divisible-by-3 theorem works for any 3 digits numbers (Hint: Express a 3 digit number as 100a + 10b + c, where 0 ≤ a, b and c ≤ 9)
3. "A number is divisible by 9 if and only if the sum of its digits is divisible by 9." True or false? Determine whether 89, 558, 51858, and 41857 are divisible by 9. Check your answers.
The prime sieve is a relatively efficient method for finding all primes less than or equal to a specified number. To find all primes less than or equal to 50, we do the following:
First, we write out the numbers 1 to 50 in a table as below
Cross out 1, because it's not a prime.
Now 2 is the smallest number not crossed out in the table. We mark 2 as a prime and cross out all multiples of 2 i.e. 4, 6, 8, 10 ...
Now 3 is the smallest number not marked in anyway. We mark 3 as a prime and cross out all multiples of 3 i.e. 6, 9, 12, 15 ...
Continue this way to find all the primes. When do you know you have found all the primes under 50? Note that this algorithm is called Sieve of Eratosthenes
The prime sieve has been applied to the table above. Notice that every number situated directly below 2 and 5 are crossed out. Construct a rectangular grid of numbers running from 1 to 60 so that after the prime sieve has been performed on it, all numbers situated directly below 2 and 5 are crossed out. What is the width of the grid?
2. Find all primes below 200.
3. Find the numbers which are divisible by 3 below 200. Did you change the width of your grid?
Infinitely many primes
To answer the question what is the largest prime number? let us first answer what is the largest natural number? If somebody tells you that is the largest natural number, you can immediately prove them wrong by telling them that is a larger natural number. You can substitute with any number other natural number and your argument will still work. This means that there is no such thing as the largest natural number. (Some of you might be tempted to say that infinity is the largest natural number. However, infinity is not a natural number but just a mathematical concept.)
The ancient Greek mathematician Euclid, had the following proof of the infinitude of primes.
Proof of infinitude of primes
Let us first assume that
- there are a finite number of primes
- there must be one prime that is greater than all others,
let this prime be referred to as n. We now proceed to show the two assumptions made above will lead to a contradiction, and thus there are infinitely many primes.
Take the product of all prime numbers to yield a number x. Thus:
Then, let y equal one more than x:
One may now conclude that y is not divisible by any of the primes up to n, since y differs from a multiple of each such prime by exactly 1. Since y is not divisible by any prime number, y must either be prime, or its prime factors must all be greater than n, a contradiction of the original assumption that n is the largest prime! Therefore, one must declare the original assumption incorrect, and that there exists an infinite number of primes.
Fun Fact -- Largest known prime
Useful Off-site Resources
Modular arithmetic connects with primes in an interesting way. Modular arithmetic is a system in which all numbers up to some positive integer, n say, are used. So if you were to start counting you would go 0, 1, 2, 3, ... , n - 1 but instead of counting n you would start over at 0. And what would have been n + 1 would be 1 and what would have been n + 2 would be 2. Once 2n has been reached the number is reset to 0 again, and so on. Modular arithmetic is also called clock-arithmetic because we only use 12 numbers to tell standard time. On clocks we start at 1 instead of 0, continue to 12, and then start at 1 again. Hence the name clock-arithmetic.
The sequence also continues into what would be the negative numbers. What would have been -1 is now n - 1. For example, consider modulo 7 arithmetic, it's just like ordinary arithmetic except the only numbers we use are 0, 1, 2, 3, 4, 5 and 6. If we see a number outside of this range we add 7 to (or subtract 7 from) it, until it lies within that range.
As mentioned above, modular arithmetic is not that different to ordinary arithmetic. For example in modulo 7 arithmetic, we have
We have done some calculation with negative numbers. Consider 5 × -6. Since -6 does not lie in the range 0 to 6, we need to add 7 to it until it does. And -6 + 7 = 1. So in modular 7 arithmetic, -6 = 1. In the above example we showed that 5 × -6 = -30 = 5, but 5 × 1 = 5. So we didn't do ourselves any harm by using -6 instead of 1. Why?
Note - Negatives: The preferred representation of -3 is 4, as -3 + 7 = 4, but using either -3 and 4 in a calculation will give us the same answer as long as we convert the final answer to a number between 0 and 6 (inclusive).
Find in modulo 11
- -1 × -5
- 3 × 7
3. Compute the first 10 the powers of 2
- 21, 22, 23, ... , 210
What do you notice?
Using the powers of 2 find
- 61, 62, 63, ... , 610
What do you notice again?
i.e. find, by trial and error (or otherwise), all numbers x such that x2 = 4 (mod 11). There are two solutions, find both .
i.e. find all numbers x such that x2 = 9 (mod 11). There are two solutions, find both.
Consider a number n, the inverse of n is the number that when multiplied by n gives 1. For example, if we were to solve the following equation
the (mod 7) is used to make it clear that we are doing arithemetic modulo 7. We want to get rid of the 5 somehow. Multiplying it by something to turn it into a 1 would do the job. Notice that
because 3 multiplied by 5 gives 1, we say 3 is the inverse of 5 in modulo 7. Now we multiply both sides by 3
So x = 2 modulo 7 is the required solution.
- The inverse of (a number) x is a number y such that xy = 1. We denote the inverse of x by x-1 or 1/x.
Inverse is unique
From above, we know the inverse of 5 is 3, but does 5 have another inverse? The answer is no. In fact, in any reasonable number system, a number can have one and only one inverse. We can see that from the following proof
Suppose n has two inverses b and c
From the above argument, all inverses of n must be equal. As a result, if the number n has an inverse, the inverse must be unique.
An interesting property of any modulo n arithmetic is that the number n - 1 has itself as an inverse. That is, (n - 1) × (n - 1) = 1 (mod n), or we can write (n - 1)2 = (-1)2 = 1 (mod n). The proof is left as an exercise at the end of the section.
Existence of inverse
Not every number has an inverse in every modulo arithmetic. For example, 3 doesn't have an inverse mod 6, i.e., we can't find a number x such that 3x = 1 mod 6 (the reader can easily check).
Consider modulo 15 arithmetic and note that 15 is composite. We know the inverse of 1 is 1 and of 14 is 14. But what about 3, 6, 9, 12, 5 and 10? None of them has an inverse! Note that each of them shares a common factor with 15!
As an example, we show that 3 does not have an inverse modulo 15. Suppose 3 has an inverse x, then we have
We make the jump from modular arithemetic into rational number arithmetic. If 3x = 1 in modulo 15 arithmetic, then
for some integer k. Now we divide both sides by 3, we get
But this cannot be true, because we know that x is an integer, not a fraction. Therefore 3 doesn't have an inverse in mod 15 arithmetic. To show that 10 doesn't have an inverse is harder and is left as an exercise.
We will now state the theorem regarding the existence of inverses in modular arithmetic.
- If n is prime then every number (except 0) has an inverse in modulo n arithmetic.
- If n is composite then every number that doesn't share a common factor with n has an inverse.
It is interesting to note that division is closely related to the concept of inverses. Consider the following expression
the conventional way to calculate the above would be to find the inverse of 3 (being 5). So
We write the inverse of 3 as 1/3, so we think of multiplying 3-1 as dividing by 3, we get
Notice that we got the same answer! In fact, the division method will always work if the inverse exists.
However, the expression in a different modulo system will produce the wrong answer, for example
we don't get 2, as 3-1 does not exist in modulo 9, so we can't use the division method.
1. Does 8 have an inverse in mod 16 arithemetic? If not, why not?
2. Find x mod 7 if x exists:
3. Calculate x in two ways, finding inverse and division
4. (Trick) Find x
5. Find all inverses mod n (n ≤ 19)
Coprime and greatest common divisor
Two numbers are said to be coprimes if their greatest common divisor (gcd) is 1. E.g. 21 and 55 are both composite, but they are coprime as their greatest common divisor is 1. In other words, they do not share a common divisor other than 1.
There is a quick and elegant way to compute the gcd of two numbers, called Euclid's algorithm. Let's illustrate with a few examples:
- Find the gcd of 21 and 49.
We set up a two-column table where the larger of the two numbers is on the right hand side as follows
We now compute 49 (mod 21) which is 7 and put it in the second row smaller column, and put 21 into the larger column.
Perform the same action on the second row to produce the third row.
Whenever we see the number 0 appear on the smaller column, we know the corresponding larger number is the the gcd of the two numbers we started with, i.e. 7 is the gcd of 21 and 49. This algorithm is called Euclid's algorithm.
- Find the gcd of 31 and 101
- Find the gcd of 132 and 200
Important to note
- The gcd need not be a prime number.
- The gcd of two different primes is 1. In other words, two different primes are always coprime.
1. Determine whether the following sets of numbers are coprimes
- 5050 5051
- 59 78
- 111 369
- 2021 4032
2. Find the gcd of the numbers 15, 510 and 375
info -- Algorithm
An algorithm is a step-by-step description of a series of actions when performed correctly can accomplish a task. There are algorithms for finding primes, deciding whether 2 numbers are coprimes, finding inverses and many other purposes.
You'll learn how to implement some of the algorithms we have seen using a computer in the chapter [[../../../Mathematical Programming/]].
Let's look at the idea of inverse again, but from a different angle. In fact we will provide a sure-fire method to find the inverse of any number. Let's consider:
- 5x = 1 (mod 7)
We know x is the inverse of 5 and we can work out it is 3 reasonably quickly. But x = 10 is also a solution, so is x = 17, 24, 31, ... 7n + 3. So there are infinitely many solutions; therefore we say 3 is equivalent to 10, 17, 24, 31 and so on. This is a crucial observation.
Now let's consider
A new notation is introduced here, it is the equal sign with three strokes instead of two. It is the "equivalent" sign; the above statement should read "216x is EQUIVALENT to 1" instead of "216x is EQUAL to 1". From now on, we will use the equivalent sign for modulo arithmetic and the equal sign for ordinary arithmetic.
Back to the example, we know that x exists, as gcd(811,216) = 1. The problem with the above question is that there is no quick way to decide the value of x! The best way we know is to multiply 216 by 1, 2, 3, 4... until we get the answer, there are at most 811 calculations, way too tedious for humans. But there is a better way, and we have touched on it quite a few times!
We notice that we could make the jump just like before into rational mathematics:
We jump into rational maths again
We jump once more
Now the pattern is clear, we shall start from the beginning so that the process is not broken:
Now all we have to do is choose a value for f and substitute it back to find a! Remember a is the inverse of 216 mod 811. We choose f = 0, therefore e = 1, d = 13, c = 40, b = 53 and finally a = 199! If f is chosen to be 1 we will get a different value for a.
The very perceptive reader should have noticed that this is just Euclid's gcd algorithm in reverse.
Here are a few more examples of this ingenious method in action:
Find the smallest positive value of a:
Choose d = 0, therefore a = 49.
Example 2 Find the smallest positive value of a:
Choose e = 0, therefore a = -152 = 669
Example 3 Find the smallest positive value of a:
Set i = 0, then a = -21 = 34. Why is this so slow for two numbers that are so small? What can you say about the coefficients?
Example 4 Find the smallest positive value of a:
Now d is not an integer, therefore 21 does not have an inverse mod 102.
What we have discussed so far is the method of finding integer solutions to equations of the form:
- ax + by = 1
where x and y are the unknowns and a and b are two given constants, these equations are called linear Diophantine equations. It is interesting to note that sometimes there is no solution, but if a solution exists, it implies that infinitely many solutions exist.
In the Modular Arithmetic section, we stated a theorem that says if gcd(a,m) = 1 then a-1 (the inverse of a) exists in mod m. It is not difficult to see that if p is prime then gcd(b,p) = 1 for all b less than p, therefore we can say that in mod p, every number except 0 has an inverse.
We also showed a way to find the inverse of any element mod p. In fact, finding the inverse of a number in modular arithmetic amounts to solving a type of equations called Diophantine equations. A Diophantine equation is an equation of the form
- ax + by = d
where x and y are unknown.
As an example, we should try to find the inverse of 216 in mod 811. Let the inverse of 216 be x, we can write
we can rewrite the above in every day arithmetic
which is in the form of a Diophantine equation.
Now we are going to do the inelegant method of solving the above problem, and then the elegant method (using Magic Tables).
Both methods mentioned above uses the Euclid's algorithm for finding the gcd of two numbers. In fact, the gcd is closely related to the idea of an inverse. Let's apply the Euclid's algorithm on the two numbers 216 and 811. This time, however, we should store more details; more specifically, we want to set up an additional column called PQ which stands for partial quotient. The partial quotient is just a technical term for "how many n goes into m" e.g. The partial quotient of 3 and 19 is 6, the partial quotient of 4 and 21 is 5 and one last example the partial quotient of 7 and 49 is 7.
The tables says three 216s goes into 811 with remainder 163, or symbollically:
- 811 = 3×216 + 163.
Reading off the table, we can form the following expressions
- 811 = 3× 216 + 163
- 216 = 1× 163 + 53
- 163 = 3× 53 + 4
- 53 =13× 4 + 1
Now that we can work out the inverse of 216 by working the results backwards
- 1 = 53 - 13×4
- 1 = 53 - 13×(163 - 3×53)
- 1 = 40×53 - 13×163
- 1 = 40×(216 - 163) - 13×163
- 1 = 40×216 - 53×163
- 1 = 40×216 - 53×(811 - 3×216)
- 1 = 199×216 - 53×811
Now look at the equation mod 811, we will see the inverse of 216 is 199.
The Magic Table is a more elegant way to do the above caculations, let us use the table we form from Euclid's algorithm
Now we set up the so-called "magic table" which looks like this initially
Now we write the partial quotient on the first row:
We produce the table according to the following rule:
- Multiply a partial quotient one space to the left of it in a different row, add the product to the number two space to the left on the same row and put the sum in the corresponding row.
It sounds more complicated then it should. Let's illustrate by producing a column:
We put a 3 in the second row because 3 = 3×1 + 0. We put a 1 in the third row because 1 = 3×0 + 1.
We shall now produce the whole table without disruption:
We can check that
- |199×216 - 811×53| = 1
In fact, if the magic table is contructed properly, and we cross multiplied and subtracted the last two column correctly, then we will always get 1 or -1, provided the two numbers we started with were coprimes. The magic table is just a cleaner way of doing the mathematics.
1. Find the smallest positive x:
2. Find the smallest positive x:
(a) Produce the magic table for 33a = 1 (mod 101)
(b) Evaluate and express in the form p/q
What do you notice?
(a) Produce the magic table for 17a = 1 (mod 317)
(b) Evaluate and express in the form p/q
What do you notice?
Chinese remainder theorem
The Chinese remainder theorem is known in China as Han Xing Dian Bing, which in its most naive translation means Han Xing counts his soldiers. The original problem goes like this:
- There exists a number x, when divided by 3 leaves remainder 2, when divided by 5 leaves remainder 3 and when divided by 7 leaves remainder 2. Find the smallest x.
We translate the question into symbolic form:
How do we go about finding such a x? We shall use a familiar method and it is best illustrated by example:
Looking at x = 2 (mod 3), we make the jump into ordinary mathematics
Now we look at the equation modulo 5
Substitute into (1) to get the following
Now look at the above modulo 7
We choose b = 1 to minimize x, therefore x = 23. And a simple check (to be performed by the reader) should confirm that x = 23 is a solution. A good question to ask is what is the next smallest x that satisfies the three congruences? The answer is x = 128, and the next is 233 and the next is 338, and they differ by 105, the product of 3, 5 and 7.
We will illustrate the method of solving a system of congruences further by the following examples:
Example 1 Find the smallest x that satisfies:
now substitute back into the first equation, we get
again substituting back
Therefore 52 is the smallest x that satisfies the congruences.
Find the smallest x that satisfies:
now solve for b
again, substitue back
Therefore 269 is the smallest x that satisfies the congruences.
1. Solve for x
2. Solve for x
*Existence of a solution*
The exercises above all have a solution. So does there exist a system of congruences such that no solution could be found? It certainly is possible, consider:
- x ≡ 5 (mod 15)
- x ≡ 10 (mod 21)
a cheekier example is:
- x ≡ 1 (mod 2)
- x ≡ 0 (mod 2)
but we won't consider silly examples like that.
Back to the first example, we can try to solve it by doing:
the above equation has no solution because 3 does not have an inverse modulo 21!
One may be quick to conclude that if two modulo systems share a common factor then there is no solution. But this is not true! Consider:
we can find a solution
we now multiply both sides by the inverse of 5 (which is 17), we obtain
obviously, k = 3 is a solution, and the two modulo systems are the same as the first example (i.e. 15 and 21).
So what determines whether a system of congruences has a solution or not? Let's consider the general case:
essentially, the problem asks us to find k and l such that the above equations are satisfied.
We can approach the problem as follows
now suppose m and n have gcd(m,n) = d, and m = dmo, n = dno. We have
if (a - b)/d is an integer then we can read the equation mod mo, we have:
Again, the above only makes sense if (a - b)/d is integeral. Also if (a - b)/d is an integer, then there is a solution, as mo and no are coprimes!
In summary: for a system of two congruent equations
there is a solution if and only if
- d = gcd(m,n) divides (a - b)
And the above generalises well into more than 2 congruences. For a system of n congruences:
for a solution to exist, we require that if i ≠ j
- gcd(mi,mj) divides (ai - aj)
Decide whether a solution exists for each of the congruences. Explain why.
- x ≡ 7 (mod 25)
- x ≡ 22 (mod 45)
- x ≡ 7 (mod 23)
- x ≡ 3 (mod 11)
- x ≡ 3 (mod 13)
- x ≡ 7 (mod 25)
- x ≡ 22 (mod 45)
- x ≡ 7 (mod 11)
- x ≡ 4 (mod 28)
- x ≡ 28 (mod 52)
- x ≡ 24 (mod 32)
To go further
This chapter has been a gentle introduction to number theory, a profoundly beautiful branch of mathematics. It is gentle in the sense that it is mathematically light and overall quite easy. If you enjoyed the material in this chapter, you would also enjoy Further Modular Arithmetic, which is a harder and more rigorous treatment of the subject.
Also, if you feel like a challenge you may like to try out the Problem Set we have prepared for you. On the other hand, the project asks you to take a more investigative approach to work through some of the finer implications of the Chinese Remainder Theorem.
Acknowledgement: This chapter of the textbook owes much of its inspiration to Terry Gagen, Emeritus Associate Professor of Mathematics at the University of Sydney, and his lecture notes on "Number Theory and Algebra". Terry is a much loved figure among his students and is renowned for his entertaining style of teaching.
What do you think? Too easy or too hard? Too much information or not enough? How can we improve? Please let us know by leaving a comment in the discussion tab. Better still, edit it yourself and make it better.