In this chapter, we will look into one of the most exciting part of mathematics, and it is also a crucial cornerstone for computer science. The inception of number theory can be traced back to ancient civilizations, but it began to emerge as a distinct mathematical discipline with the work of the Greek mathematician Euclid. His monumental work, “Elements,” laid the groundwork for the study of prime numbers and proved fundamental theorems, such as the infinitude of primes, which are still central to number theory today. The nature of whole numbers, especially the intriguing properties of prime numbers---the building blocks of all natural numbers---has fascinated mathematicians for centuries. Over time, the field has expanded to include a rich array of topics such as the distribution of primes, the solutions of Diophantine equations, modular arithmetic, and the exploration of number-theoretic functions like the Riemann zeta function. Number theory’s initial focus on prime numbers and divisibility has blossomed into a diverse and vibrant branch of mathematics, with applications ranging from cryptography to the theory of chaos.
Divisibility and Modular Arithmetic
We begin with divisibility because it supports the Fundamental Theorem of Arithmetic, greatest common divisors, least common multiples, modular arithmetic, and many elementary cryptographic constructions. The same ideas also appear when studying integer solutions of equations and the structure of rings and fields.
Division and Divisibility
To figure out problems related to Divisibility, we must figure out the definition and properties of Division. We were taught in the primary school that a division is an operation that divides a number to a certain part. For instance, , and . Sometimes, the division produce an integer as result, while sometimes not. We define division as follows:
The division of a number by a non-zero number is denoted by or , and it gives the quotient and possibly a remainder . The operation can be written as: where and .
In , clearly we have , with and . For , integer division gives , so and , while ordinary real division gives . We will distinguish these two operations below.
True division is concerned with the quotient including the remainder as a fractional part. In true division, when is divided by , the quotient is a real number that can be represented as:
You may find that true division doesn’t have a remainder. This is just because the purpose of these two operations are different, as true division only focus on the scale of each part of , but division involves the divisibility and remainder, which will be discussed further in this chapter.
Now that we have defined division and true division, you may understand the following definition of divisibility easier.
If and are integers with , we say that divides if there is an integer such that . Equivalently, is an integer. When divides , we say that is a factor or divisor of , and that is a multiple of . The notation denotes that divides . We write when does not divide .
For example, we have , because gives an integer, however, , as the answer cannot be represented as integer. Besides, we have:
Let and be positive integers. How many positive integers not exceeding are divisible by ?
Solution: The positive integers divisible by are all the integers of the form , where is a positive integer. Hence, the number of positive integers divisible by that do not exceed equals the number of integers with , or with . Therefore, there are positive integers not exceeding that are divisible by .
Divisibility holds the following properties, which could be proven directly.
Let , , and be integers, where , then:
-
if and , then
-
if then for all integers
-
if and , then
Since and , there exist integers and such that and . Therefore, , and since is an integer, it follows that .
Given , there exists an integer such that . For any integer , . Since is an integer (because the product of two integers is an integer), .
If and , then there exist integers and such that and . Substituting the expression for into the equation for gives . Since is an integer, .
With this we have the following conclusion.
if , , and are integers, where , such that and , then whenever and are integers.
This could be proven in direct proof, which you will finish in the exercise.
Modular Arithmetic
In this section, we will focus on the remainder of division, as well as modular arithmetic. In the definition of division, we involved and , which denotes the quotient and the remainder of the operation. We use the following notations to denote each of both.
For , .
Besides, when is an integer and is a positive integer, we have .
What are the quotient and remainder when 93 is divided by 9?
Solution: . , .
The quotient is
The remainder is
What are the quotient and remainder when -93 is divided by 9?
Solution: . , .
Remember that we must make sure as we defined earlier, even though . But remainder could be positive in other division algorithm, which we will discuss in the exercise.
We have already introduced the notation to represent the remainder when an integer is divided by the positive integer . We now introduce a different, but related, notation that indicates that two integers have the same remainder when they are divided by the positive integer . But why we need to find and study the numbers with the same remainder by dividing the same positive integer? Studying numbers that yield the same remainder when divided by a given positive integer is a fundamental part of number theory; later you will understand why say so.
If and are integers and is a positive integer, then is congruent to modulo if divides . We use the notation to indicate that is congruent to modulo . We say that is a congruence and that is its modulus (plural moduli). If and are not congruent modulo , we write .
Do note that mod and mod are different notations. The first represents a relation on the set of integers, whereas the second represents a function. However, they are still related.
Let and be integers, and let be a positive integer. if and only if = .
First, suppose . By definition of congruence modulo , divides , which means there exists some integer such that .
Dividing and by , they both leave the same remainder , since and for some integers and . The remainder in both cases is the same because the difference is a multiple of , which does not affect the remainder.
Conversely, if , then both and leave the same remainder when divided by . Denote this common remainder as .
We can write and for some integers and . Subtracting these two equations, we get , which shows that is a multiple of .
Therefore, divides , and by definition of congruence modulo , we have .
This completes the proof.
Remember, when we say if and only if, we need proof from each of the both statements to the other.
Let be a positive integer. The integers and are congruent modulo if and only if there is an integer such that .
The proof is similar and not complex, try to prove it in the exercise.
Let be a positive integer. If and , then and
We use a direct proof. Because and , by Theorem 4 there are integers and with and . Hence, and Hence, and
Because and , it follows that and that
Let be a positive integer and let and be integers. Then and
By the definitions of and of congruence modulo , we know that and . Hence, and The equalities in this corollary follow from these last two congruence.
We can define arithmetic operations on , the set of nonnegative integers less than , that is, the set . In particular, we define addition of these integers, denoted by , by where the addition on the right-hand side of this equation is the ordinary addition of integers, and we define multiplication of these integers, denoted by , by where the multiplication on the right-hand side of this equation is the ordinary multiplication of integers. The operations and are called addition and multiplication modulo and when we use these operations, we are said to be doing arithmetic modulo .
Use the definition of addition and multiplication in to find and .
Solution: Using the definition of addition modulo 11, we find that and Hence, and .
sometimes, normal notations are also used to express this calculation with subscript.
Exercises
Prove corollary div1 that if , , and are integers, where , such that and , then whenever and are integers.
By theorem Properties of Divisibility, and gives us and (property 2). Hence, (property 1). This completes the proof.
Prove theorem mod2, you may use other theorems or corollary in this chapter.
If , that means we have . There must be an integer , such that (theorem mod2). Conversely, if we have an integer , such that , we have . Hence, , .
show that for integer , and then .
means that for some integer , so we have , this means .
Prove that if and are integers and divides , then is odd or is even.
We could try proof by contrapositive. Suppose for is even and is odd, . Then for some integer . Make , then there should be . However, in this case we have , meaning that is not an integer, which contradict the assumption. This completes the proof.
Prove that if is a positive integer, then .
Consider any positive integer . We know that can be expressed in one of the following forms where is an integer:
Now, we examine modulo 4 for each case: Adding 2 to in each case yields: In both cases, does not yield a remainder of modulo . Thus, it cannot be divisible by .
Therefore, we have proven that for any positive integer , the expression is not divisible by .
Suppose that and are integers, , and . Find the integer with such that
-
.
-
.
-
.
-
.
-
.
-
.
Solution: This problem is equivalent to asking for the right-hand side mod 19. So we just do the arithmetic and compute the remainder upon division by 19.
Let be a positive integer. Show that if .
Assume that . This means that , say , so that . Now let us compute . We know that for some nonnegative less than (namely, ). Therefore, we can write . By definition, this means that must also equal . That is what we wanted to prove.
Show that if and ,, , then
Since , by definition there exists an integer such that . Now, since and , we have and for some integers and . Also, implies for some integer .
Substituting these into our first equation we get
Dividing through by we obtain
This can be rewritten as
Since is an integer, this shows that is congruent to modulo , which is precisely
Hence, the statement is proven.
Prove that if and are integers such that and , then 8 divides .
Given and , we need to prove that 8 divides .
First, we find :
Next, we calculate :
Then, we calculate :
Finally, we calculate :
Since , it follows that 8 divides .
Number Representations and Algorithms
In everyday life, we use decimal notation to express integers. Though this is not for all cases, as we are using a 60 base system for time. However, in computer science, binary, octal, and hexadecimal systems are widely used for number representation. The reason is that binary system consist of only 0 and 1, as we have mentioned in Boolean algebra, this system is perfect for logic operations in side the computer. What’s more, 0 and 1 could be easily represented by the on and off of tiny switches in the integrated circuits. This chapter looks into the representation of number in different bases and their relationship, with a tress on binary representation that computer system uses. Meanwhile, we will go through algorithm of some operations between number, and analyze them accordingly.
Representations of Numbers and Base Conversion
In whichever base, a number could be expressed using the exponent of the base.
Let be an integer greater than 1. Then if is a positive integer, it can be expressed uniquely in the form:\ \ where is a nonnegative integer, are negative integers less than b, and
For example, 1024 could be interpreted as . Besides, the base of number constraints the possible numbers to be used on the bits. For example, under decimal system, we cannot take 10 as one digit, instead it is a number with two digits 1 and 0, because for bits under decimal system, the maximum only goes to 9. Therefore, you could take it as a fact that for a system of base , the biggest value for one bit is . Similarly, we see only 0 and 1 in binary, 1-7 in ocatl, 1-15 in hexadecimal expression.
To indicate the base of a number, we use the following subscript.
We use to show the base of a number, where is the base number.
The other important fact is that numbers are just numbers, base is only the way we gauge them. However you change , to whatever base, it is still 121 in decimal, but just expressed in a different way.
Binary, Octal, and Hexadecimal Expression
In binary expansion, the base on any integer is 2, that is to say, the number in each digit is either 0 or 1. We can expand binary integer in the same ways as mentioned in last section.
What is the decimal expansion of the integer that has as its binary expansion?
has nine digits, so we have:\ =
Decimal expansion of octal expansions could be calculated in the same way as the binary expansion. However, Sixteen different digits are required for hexadecimal expansions. Usually, the hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, where the letters A through F represent the digits corresponding to the numbers 10 through 15 (in decimal notation).
What is the decimal expansion of the number with hexadecimal expansion ?
In hexadecimal cases, the only difference is that capital latters are used to represent two-digit number in one digit. We still have:\ =
NOTICE: Each hexadecimal digit can be represented using four bits. For instance, we see that = because = and . Bytes, which are bit strings of length eight, can be represented by two hexadecimal digits.
Base Conversion
Base conversion of Integer
Now we have learned how to express numbers in different base systems, but is there any way to convert them from one base to the other? You may have realized that a general solution is to convert the number back to decimal form, and then to the target base. Yes, it works, but can we make it better? One way to this is to use the general base conversion algorithm. The most common algorithm to constructing the base expansion of an integer n is as follows:\ First, divide by to obtain a quotient and remainder, that is:\
The remainder, , is the rightmost digit in the base b expansion of . Next, divide by toobtain:\
We see that is the second digit from the right in the base b expansion of n. Then, we just continue this process until we obtain a quotient equal to zero. This algorithm produces the base digits of from the right to the left.
Find the hexadecimal expansion of .
\ \ \ \ \
Therefore,
This method is equivalent to the following pseudocode.
$digits \gets$ empty list $remainder \gets n \bmod b$ Append $remainder$ to $digits$ $n \gets \left\lfloor n / b \right\rfloor$ $digits \gets$ reverse $digits$ **return** $digits$Base Conversion of Float
The previous algorithm only deals with integers, so we need a different approach for decimals. The algorithm for converting a floating-point number from base 10 to base is given as follows:
$integerPart \gets \lfloor number \rfloor$ $fractionalPart \gets number - integerPart$ $baseInteger \gets \Call{ConvertIntegerToBase}{integerPart, targetBase}$ $baseFraction \gets ``"$ $fractionalPart \gets fractionalPart \times targetBase$ $baseFraction \gets baseFraction + \lfloor fractionalPart \rfloor$ $fractionalPart \gets fractionalPart - \lfloor fractionalPart \rfloor$ $baseInteger + ``." + baseFraction$Convert the floating-point number 12.375 from base 10 to base 2.
-
Integer part: 12 in base 10 is 1100 in base 2.
-
Fractional part: 0.375 in base 10 to base 2.
-
The fractional part in base 2 is .011.
Therefore, is .
Also, when a number consist of both integer and decimal parts, we just deal with them separately and them put them back together later. You will see these exercises in the problem set.
Base Conversion between Binary, Octal, and Hexadecimal number
The base conversion between Binary, Octal and Hexadecimal numbers are much easier.
Figure pending: Binary, Octal and Hexadecimal Representation
The conversion between binary, octal, and hexadecimal systems is straightforward because the bases of these systems (2 for binary, 8 for octal, and 16 for hexadecimal) are related by powers of 2. Specifically:
-
Octal digits correspond to three binary digits since . Each octal digit can be directly mapped to a unique combination of three binary bits.
-
Hexadecimal digits correspond to four binary digits since . Each hexadecimal digit can be directly mapped to a unique combination of four binary bits.
This relationship allows for simple grouping of binary bits into sets of three or four to convert to octal or hexadecimal, respectively, without any complex calculation or division.
Find the octal and hexadecimal expansions of and the binary expansions of and .
Solution: To convert into octal notation we group the binary digits into blocks of three, adding initial zeros at the start of the leftmost block if necessary. These blocks, from left to right, are 011, 111, 010, 111, and 100, corresponding to 3, 7, 2, 7, and 4 respectively. Consequently, we get
We do the hexadecimal convention in the same way. These blocks, from left to right, are 0011, 1110, 1011, and 1100, corresponding to the hexadecimal digits 3, E, B, and C, respectively. Consequently,
NOTE: The conversion could be done inversely in the same way. If the number of bit is not the multiple of 4 when you are converting between 2 and 16 base number, fill those missing digits/bits with 0.
Whether you noticed or that the base conversion, essentially, is about division and modular arithmetic that we just learned? The general base conversion algorithm could be simplified to the following algorithm, where denotes the number to be converted and is the target base.
$q \gets n$ $k \gets 0$ $a_k \gets q \mod b$ $q \gets \lfloor q / b \rfloor$ $k \gets k + 1$ **return** $(a_{k-1}, \ldots, a_1, a_0)$Operation Algorithms of Number
This section discusses algorithm of basic operation between numbers, of base2. In section, we express the binary number in the form of where and each have n bits.
Addition Algorithm
Consider the problem of adding two integers in binary notation. A procedure to perform addition can be based on the usual method for adding numbers with pencil and paper. This method proceeds by adding pairs of binary digits together with carries, when they occur, to compute the sum of two integers. This procedure will now be specified in detail.
To add and , first add their rightmost bits. This gives where is the rightmost bit in the binary expansion of and is the carry, which is either 0 or 1. Then add the next pair of bits and the carry, where is the next bit (from the right) in the binary expansion of , and is the carry. Continue this process, adding the corresponding bits in the two binary expansions and the carry, to determine the next bit from the right in the binary expansion of . At the last stage, add , , and to obtain . The leading bit of the sum is . This procedure produces the binary expansion of the sum, namely, . Consider the binary addition of two numbers, and .
The addition process is similar to that used in decimal addition, but it is performed in base 2. Below is the columnar addition process:
+
Let’s perform the addition step by step:
-
Start with the rightmost bits (least significant bits). Add . Since this is base 2, . Write down the and carry the over to the next column.
-
Move to the next column. Add (including the carry). This equals . Write down the and carry the .
-
In the next column, add . This equals . Write down the and carry the .
-
For the leftmost bits (most significant bits), add . This equals . Write down the and carry the to a new column to the left.
-
Write down the carry.
The final result is .
This algorithm’s pseudocode is as listed below.
$c \gets 0$ $d \gets \left\lfloor (a_j + b_j + c)/2 \right\rfloor$ $s_j \gets a_j + b_j + c - 2d$ $c \gets d$ $s_n \gets c$ **return** $(s_{n}s_{n-1}\ldots s_1s_0)_2$Time Complexity: The time complexity of the binary addition algorithm is , where is the number of bits in the binary representation of the inputs.
Consider the binary addition algorithm which consists of a single loop that iterates times, where is the number of bits in the binary representations of the two integers being added.
Within the loop, the algorithm performs a constant number of operations for each bit:
-
An addition of the -th bits of the two numbers .
-
An addition of the carry from the previous step .
-
A division by 2 to compute the new carry .
-
A subtraction to determine the -th bit of the sum .
-
An assignment of the new carry .
Since each of these operations has a constant time complexity, and they are all executed once for each bit, the overall time complexity of the loop is linear with respect to the number of bits. Therefore, the time complexity of the entire algorithm is .
Note that this analysis assumes that basic arithmetic operations (addition, division by 2, subtraction) can be performed in constant time.
Multiplication Algorithm
Using the same representation of binary number and , we can define binary multiplication as . The binary multiplication algorithm works similarly to traditional pencil-and-paper multiplication, but with binary digits. Given two binary numbers, we multiply each bit of the second number by the first number, shifting the result left for each subsequent bit.
$c \gets 0$ $d \gets \left\lfloor (a_j + b_j + c)/2 \right\rfloor$ $s_j \gets a_j + b_j + c - 2d$ $c \gets d$ $s_n \gets c$ $(s_{n}s_{n-1}\ldots s_1s_0)_2$Find the product of and . First note that To find the product, add and . Carrying out these additions (using Algorithm 2, including initial zero bits when necessary) shows that .
Time Complexity: The time complexity of binary multiplication is , where is the number of bits in the binary numbers. This is because each bit of one number is multiplied by each bit of the other number, resulting in multiplications for each of the bits.
Algorithm for Div and Mod
The following algorithm is used to find the quotient and remainder of . This is a more general algorithm as it could handle the cases where a is negative
$q \gets 0$ $r \gets |a|$ $r \gets r - d$ $q \gets q + 1$ $r \gets d - r$ $q \gets -(q + 1)$ $(q, r)$Modular Exponentiation Algorithm
An important application of modular arithmetic is finding efficiently, which is crucial for cryptography. could be a huge number that takes a lot of time to calculate, so we need this algorithm to speed up this process. to implement this algorithm, we need to use the binary expansion of the number . Since
This shows that to compute , we need only compute the values of . Once we have these values, we multiply the terms in this list, where .(For efficiency and to reduce space requirements, after multiplying by each term, we reduce the result modulo
Compute \ Solution: To compute we first note that , so that . By successively squaring, we find that , , and . Consequently, .
Now we have already finished the part of algorithm to find . With this, we can define the algorithm to find . The pseudocode of the algorithm is in the listing below.
$x := 1$ $power := b \mod m$ **then** $x := (x \cdot power) \mod m$ $power := (power \cdot power) \mod m$ **return** $x$ $x$ equals $b^n \mod m$Find the value of using the Algorithm.
Solution: The algorithm starts by initializing and . It then calculates for by repeatedly squaring and reducing modulo 645. When the th bit of 644 (in binary, ) is 1, the algorithm multiplies the current by and reduces the product modulo 645. The steps are as follows:
: , so and . : , so and . : , so and . : , so and . : , so and . : , so and . : , so and . : , so and . : , so and . : , so .
Thus, the value of is 36.
Time Complexity of Algorithm 5
The time complexity of Algorithm modulare is determined by the number of iterations in the for loop, which is equal to the number of bits in the binary representation of the exponent . In each iteration, the algorithm performs a constant number of modular multiplications and squarings. Therefore, the time complexity of Algorithm modulare is , where is the exponent. This is a significant improvement over the naive method of modular exponentiation, which has a time complexity of . The fast modular exponentiation algorithm is particularly useful in cryptographic applications, such as the RSA algorithm, where the exponents are typically large numbers.
To prove that the time complexity of Algorithm modulare is , we can analyze the number of operations performed by the algorithm in relation to the size of the input exponent .
Let be the exponent in the modular exponentiation problem, and let be the number of bits in the binary representation of . We can express as:
The algorithm iterates through the bits of from right to left (from the least significant bit to the most significant bit). In each iteration, the algorithm performs the following operations:
-
If , it performs a modular multiplication to update the value of .
-
It performs a modular squaring to update the value of .
The modular multiplication and squaring operations can be performed in time using a constant number of arithmetic operations modulo .
Since the algorithm iterates through all bits of , the total number of iterations is . Therefore, the time complexity of the algorithm is proportional to , which is the number of bits in the binary representation of .
We know that the number of bits in the binary representation of is . Thus, .
Consequently, the time complexity of Algorithm modulare is .
This logarithmic time complexity makes Algorithm modulare (fast modular exponentiation) much more efficient than the naive method of modular exponentiation, which has a linear time complexity of .
Exercises
Primes and Greatest Common Divisors
In previous chapter, we learned the properties of division and divisibility, as well as modular arithmetic. These are the most essential parts of the whole number theory. In this section , we will discuss primes and its property. Prime is not something unfamiliar to us, since some may even have learned that from the kindergarten or primary school. We will look into the Algorithms that could help is find primes and delve into the algebraic properties of prime later. All these are foundations of cryptography.
Primes and Related Algorithms
To learn prime, of course we need to recap on its definition.
An integer greater than 1 is called prime if the only positive factors of are 1 and . A positive integer that is greater than 1 and is not prime is called composite.
Note that, by this definition, 1 is not a prime, as it is only 1 as the only factor.
The reason why prime numbers are so fascinating to mathematicians is that they have so many interesting and unique property, even except for what we have seen in its definition. Below is what we call the fundamental theorem of arithmetic.
For every integer , there exists a unique factorization into prime numbers, up to the order of the factors. Specifically, can be expressed as where are prime numbers and are positive integers. This factorization is unique, apart from the order of the prime factors.
We prove the theorem in two parts: existence and uniqueness.
Existence: We prove by mathematical induction that every integer greater than 1 can be written as a product of primes.
Base Case: For , the statement holds true since 2 is itself a prime number.
Inductive Step: Assume the statement holds for all integers greater than 1 and less than . Now consider the integer .
-
If is prime, then it is trivially a product of primes (itself).
-
If is not prime, it can be written as where . By the inductive hypothesis, both and can be factored into a product of primes. Therefore, can also be expressed as a product of primes by combining the prime factorization of and .
This completes the proof of existence.
Uniqueness: Assume, for the sake of contradiction, that there are two distinct prime factorization of : where and are prime numbers, and are positive integers. To proceed to the rest of the proof, we need to use Euclid’s lemma.
lemma:
Let be a prime number. If divides the product , where and are integers, then divides or divides .
Proof of Euclid’s lemma: Assume is a prime that divides but does not divide . We need to show that must divide .
Since does not divide , the greatest common divisor (gcd) of and is 1, i.e., . According to Bezout’s identity, there exist integers and such that:
Multiplying both sides of the equation by , we get:
Remark: If this proof is not yet understandable, skip it and return to it after the discussion of linear combinations and this theorem.
Since divides (by assumption), divides . Also, obviously divides . Hence, divides the sum , which means divides .
This completes the proof, showing that if divides and does not divide , then must divide , in accordance with Euclid’s lemma.
By Euclid’s lemma, if a prime divides the product of two numbers, it must divide at least one of those numbers. Thus, must divide some on the right-hand side. Since is prime, we conclude that . Applying this argument symmetrically and repeatedly, we find that each set of prime factors must be identical to the other, contradicting the assumption of two distinct factorization.
Therefore, the prime factorization of any integer greater than 1 is unique, up to the order of the factors, which completes the proof of the Fundamental Theorem of Arithmetic.
100 can be taken as . Both 2 and 5 are primes.
Now that we know these interesting properties of prime and its significance, how do we find primes, not just correctly, but also efficiently? The most basic algorithm that anyone could find is that we can actually check numbers one by one. To find whether an integer is prime, what we need to do is to check every number from 2 to , and use them to divide one by one. If anyone of them divides , then is not prime, and vice versa.
Trial Division
We actually can apply a more efficient way to determine whether an integer is prime or not. Considering the following theorem.
If is a composite integer, then has a prime divisor less than or equal to .
If is composite, by the definition of a composite integer, we know that it has a factor with . Hence, by the definition of a factor of a positive integer, we have , where is a positive integer greater than 1. We will show that or . If and , then , which is a contradiction. Consequently, or . Because both and are divisors of , we see that has a positive divisor not exceeding . This divisor is either prime or, by the fundamental theorem of arithmetic, has a prime divisor less than itself. In either case, has a prime divisor less than or equal to .
Below is the pseudocode for this procedure.
**false** **false** **true**Show that is prime.
textbfSolution: Primes less than are 2, 3, 5, 7. 101 is not divisible by any of them, so it is not composite, and thus it is prime.
We also need an efficient algorithm to factorize a give number to primes. Here is how is works. It works as follows.
$factors \gets \text{an empty list}$ Add $p$ to $factors$ $n \gets n / p$ **break** Add $n$ to $factors$ $factors$Find the prime factorization of 8964.
Solution:
-
8964 is even, so start with 2: .
-
4482 is also even, divide by 2 again: .
-
2241 is not divisible by 2. The next primes to try are 3, 5, 7, 11, and so on. We find that 2241 is not divisible by any of these primes until we reach 31.
-
2241 divided by 31 gives us 71, which is a prime number.
Thus, the prime factorization of 8964 is , or in exponent form, .
There are also other method to finding prime numbers or tell whether a number is prime or not. If you are willing to delve into it, you may check Sieve of Eratosthenes, Sieve of Ktkin. These are only small part of all possible method, which we will learn later, such as Fermat’s Little Theorem in solving congruence, as well as Monte Carlo method in probability.
Greatest Common Divisors and Least Common Multiples
Now we will discuss yet another primary school topic, GCD and LCM. Briefyly recap their definitions:
Let and be integers, not both zero. The largest integer such that and is called the greatest common divisor of and . The greatest common divisor of and is denoted by gcd.
Find gcd and gcd.
These are easy-to-solve problems. The largest number that divides 12 and 24 is 6, so gcd,while 17 and 22 do not have common divisor other than 1, so gcd.
For 17 and 22, we have gcd. In this case, we call that they are Relatively Prime, because their greatest common divisor is 1.
We can generalize this idea to pairwise Relatively prime.
The integers are pairwise relatively prime if whenever
For example, , , and are pairwise relatively prime because . A sequence is pairwise relatively prime exactly when every pair of distinct terms has greatest common divisor .
The other way to find gcd of two number is using their prime factorization. Suppose that the prime factorizations of the positive integers and are . where each exponent is a nonnegative integer, and where all primes occurring in the prime factorization of either or are included in both factorizations, with zero exponents if necessary. Then gcd is given by where represents the minimum of the two numbers and y. To show that this formula for is valid, we must show that the integer on the right-hand side divides both and , and that no larger integer also does. This integer does divide both and , because the power of each prime in the factorization does not exceed the power of this prime in either the factorization of or that of . Further, no larger integer can divide both and , because the exponents of the primes in this factorization cannot be increased, and no other primes can be included.
Find .
The same prime-factorization method gives the least common multiple of two integers. The Fundamental Theorem of Arithmetic guarantees that every integer greater than has a unique factorization into primes.
The least common multiple of the positive integers and is the smallest positive integer that is divisible by both and . The least common multiple of and is denoted by lcm.
Suppose the prime factorizations of and are given by where and are the exponents of the prime factors of and , respectively.
The product can be expressed as a prime factorization:
From this, we can deduce that any common multiple of and must be a product of their prime factors raised to at least the maximum exponent found in either or . Therefore, the can be expressed as This ensures that is divisible by both and , and it is the smallest such number with this property.
Find lcm.
Have you noticed, that is actually the product of and ? Becuase the order of each term in the prime factorization of is a sum of two number, what ever which number is the maximum of the minimum, we always have the order of . For 120 and 500 we have
Let and be positive integers. Then lcm
The Euclidean Algorithm
Greatest Common Divisors as Linear Combinations
The greatest common divisor of two integers and can be expressed in the form where and are integers. In other words, can be expressed as a linear combination with integer coefficients of and .
This property of GCD is exactlly the Bézout’s Theorem, which states that:
Let and be integers, not both zero. There exist integers and such that where denotes the greatest common divisor of and . The integers and are known as Bézout coefficients. the equation is called Bézout’s identity.
The proof of Bézout’s identity uses the property that for nonzero integers and , dividing by leaves a remainder of strictly less than and . .Then by repeated applications of the Euclidean division algorithm, we have , , , ,
where the is the last nonzero remainder in the division process. Now, as illustrated in the example above, we can use the second to last equation to solve for as a combination of and . Unfolding this, we can solve for as a combination of and etc. until we eventually write as alinear combination of and . Since is the last nonzero remainder in the division process, it is the greatest common divisor of and ,which proves Bézout’s identity.
You can access a more detailed proof here.
Bezout’s Theorem is closely related to Linear Diophantine Equations, which we will discuss further in solving linear congruence.
We use a example to explain further on the theorem. Recall that Euclidean algorithm is actually a recursive algorithm, to find gcd of and , it requires multiple usage of the algorithm.
Use the Euclidean algorithm to find the greatest common divisor of 1022 and 400.
Solution: In this way, we find easily. Writing the step-by-step of using Euclidean like this is what we call the Extended Euclidean Algorithm.
Notice further that as the terms in the extended algorithm could be expressed by previous lines, we can finally get a linear combination of the gcd over 1022 and 400. In this case, we have .
Now consider an equivalent expression for the problem. Find integers and such that . In this case, we do exactly the same thing, and straightforward, we have and .
There is still another equivalent expression to this, and it will be discussed with linear congruence in the next section.
Exercises
Solving Congruence
Earlier in this chapter, we introduced divisibility, and thus defined division and modular arithmetic, as well as modular congruence. We have also introduced algebraic properties of congruence, and surprisingly, many of which are just like “copying” from the real number , or we generally say, normal algebra system. Now think about how we learn math for real number. We learnt all the way from basic operations, and finally we just do not use the numbers anymore in the expression, but in stead, letters, and we call this algebra. Now that modular congruence shares so many basic properties with that, can we extend to more algebra on modular congruence? This section introduces solving equation, or only linear equations, of modular congruence, and it has much to do with Euclidean algorithm.
Linear Congruence
Congruence of the form as follows is called Linear Congruence, where , and is the variable to be solved. To solve this congruence, we need to find , which we call inverse of a modulo m if , such that .
If we are to find the of a given expression, what kind of solution we will get? Do we get specific solution or infinitely many solutions? The fact is that we will get infinitely many solutions, since modular congruence has periodicity.
If and are relatively prime integers and , then an inverse of modulo exists. Furthermore, this inverse is unique modulo . (That is, there is a unique positive integer that is an inverse of modulo and every other inverse of modulo is congruent to modulo .)
By Bezout’s Theorem, because , there are integers and such that This implies that Because , it follows that Consequently, is an inverse of modulo .
Now we try to prove the uniqueness of as an inverse of modulo . Suppose there are other integers than () that satisfies So, by definition of modular congruence we have and , which gives So , and this means that for some integer must be true. If that is true, then is also multiple of , which means . Now recall our assumption that , so for some integer refutes our assumption. Therefore, there is a unique positive integer that is an inverse of a modulo and every other inverse of modulo is congruent to modulo m.
Find an inverse of 101 modulo 5000.
Solution:
we present all steps used to compute an inverse of 101 modulo 5000. First, we use the Euclidean algorithm to show that . Then we will reverse the steps to find Bézout coefficients and such that . It will then follow that is an inverse of 101 modulo 5000. The steps used by the Euclidean algorithm to find are Because the last nonzero remainder is 1, we know that . We can now find the Bezout coefficients for 101 and 5000 by working backwards through these steps, expressing the gcd of 101 and 5000 as in terms of each successive pair of remainders. In each step we eliminate the remainder by expressing it as a linear combination of the divisor and the dividend. We obtain
That tells us that and are Bezout coefficients of 5000 and 101, and is an inverse of 101 modulo 5000.
What are the solutions of the linear congruence ?
We know that -99 is a modular inverse of . So we multiply the inverse on the both side, this gives , so . From here we can see that is not a single number, but a set of numbers. We can have. So the general solution is , where is some integer, and is one of the specific solution we can find.
Great, now you can solve any solutions for any linear congruence, as long as it is solvable (has inverse). But can we generalize this problem? Because in the previous discussion of solving linear congruence and finding the inverse are all based on the condition that the two numbers are coprime, i.e., . What will be the case when they are not coprime?
Actually, solving linear congruence is a subset of a greater concept, Diophantine Equation.
A Diophantine equation is an equation or a system of equations that allows for polynomial expressions in several variables and requires the solutions to be integers. These equations are studied within number theory and are named after Diophantus of Alexandria, a Greek mathematician. Specifically, a Diophantine equation can be interpreted by the following expression. Where , , , .
You may realize at the first glance that this equation is hard to solve and has infinitely many solutions, because for the most basic system of linear equation, we can only get specific solution when the number of unknowns is equal to the number of equations in the system. But no worries, we discuss only the simplest form of this type of equation for now, which is Isn’t it familiar to you? This is exactly what were shown in Bezout’s Theorem (you may check theorem Bezout) This means that, as long as we are finding the relation between between a pair of number with their GCD, we are doing exactly the same thing as solving linear congruence, because the latter is a subset of the former, as Diophantine equation.
Now let’s work out the general solution of such equation. Consider the linear Diophantine equation
where , , and are given integers, and and are unknown integers that we want to solve for.
Step 1: Finding a particular solution
By the Extended Euclidean Algorithm, we can find integers and such that
Step 2: The general solution form
If is a multiple of , say , then by multiplying the equation by , we get a particular solution to :
Now, consider that for any integer , the following holds:
where .
This is because the multiples of added to and multiples of subtracted from will cancel each other out when multiplied by and , respectively.
Step 3: General solution
Thus, the general solution to the equation can be expressed as:
where are any integer and . This represents an infinite set of solutions if and are coprime.
Now consider the cases for solutions, when are coprime (), there must be integer solutions for the equation, as shown in the proof, because 1 is a divisor of any integer. However, when is not a multiple of , we cannot find any integer solution. As for other general cases, i.e., , but , there are integer solutions.
Now that we have known the idea of Diophantine Equation, we can relate the concept to linear congruence easily.
Solving linear congruence is a subproblem of solving linear Diophantine equation. Suppose we are looking for linear combination of , which is equivalent to solving this Diophantine equation. This is equivalent to find .
means that . By division algorithm , , where is the quotient and . , and thus , where . So we have shown that solving linear congruence could be treated as solving a Diophantine Equation.
Solve
Solution:
We can straightaway treat it as solving the Diophantine equation We need to know their gcd, so we use extended Euclidean algorithm.
By Bezout theorem, we use substitution repetitively to get the linear combination of their gcd in terms of 400 and 1022, which is . Because 8 is multiple of 2, so we can get by , which is a set of specific solution ().
With the specific solution, we can get the general solution:
The Chinese Remainder Theorem
In the last section, we relate linear congruence to linear equation. Now we will try to relate it to system of linear equations. Recall that a system of linear equations is a collection of one or more linear equations involving the same variables.
In the context of real numbers, a system of linear equations in unknowns can be written as: where and are real numbers.
Just a kind reminder that “Linear” basically means the order of polynomial is at most 1, just in case some don’t know the definition.
Similarly, a system of linear congruences is a collection of linear congruences in the same variables over a ring of integers modulo . A system of linear congruences in unknowns can be written as: where , , and are integers. The goal in both cases is to find values for the unknowns that simultaneously satisfy all the equations or congruences in the system.
Actually, we cannot solve such complex problems, which requires further knowledge on matrix and linear algebra. However, just like what we do to Diophantine Equations, we are trying to find solution for a specific case of basic form, which, in this case, is discussed in Chinese Remainder Theorem. In the first century, the Chinese mathematician Sun-Tsu asked: There are certain things whose number is unknown. When divided by 3, the remainder is 2; when divided by 5, the remainder is 3; and when divided by 7, the remainder is 2. What will be the number of things?
This problem could be transfered in the a system of linear congruences that The algorithm to find the solution for such problem is known as Chinese Remainder Theorem.
Let be pairwise relatively prime positive integers greater than one and arbitrary integers. Then the system has a unique solution modulo (That is, there is a solution with , and all other solutions are congruent modulo to this solution.)
To establish this theorem, we need to show that a solution exists and that it is unique modulo . We will show that a solution exists by describing a way to construct this solution, and then we will prove that the solution is unique modulo .
Existence of a solution: To construct a simultaneous solution, first let for . That is, is the product of the moduli except for . Because and have no common factors greater than 1 when , it follows that . Consequently, by Bézout’s identity, we know that there exist integers and such that This implies that (refer to theorem exist_inverse) Where is one of the unique modular inverse of . To construct a simultaneous solution, form the sum
We will now show that is a simultaneous solution. First, note that because whenever , all terms except the th term in this sum are congruent to 0 modulo . Because , we see that for . We have shown that is a simultaneous solution to the congruences.
Uniqueness of the solution modulo :
Suppose that and are two solutions to the system of congruences. Then, for each , we have This implies that for all . Since are pairwise coprime, by the Chinese Remainder Theorem for Ideals, we have where . This proves that the solution is unique modulo .
Solve where , , are pairwise coprime
we can use the Chinese Remainder Theorem. The solution is: where and satisfies for each . The solution is the smallest positive integer that leaves a remainder of 2 when divided by 3, a remainder of 3 when divided by 5, and a remainder of 2 when divided by 7.
This is indeed a general solution to such problem, however, you may have already realized that finding modular inverse for a given number is not that easy. And also, when the problem scale up, the complexity of computing is not ideal. Hence, we introduce back substitution as a shortcut, here is how it works.
Solving by back substitution.
By the definition of modular congruence, is equivalent to for some integer . Substituting this into the second modular congruence gives us Subtracting 2 on both side we have Now we can find that is actually a modular inverse of 3 by 5, and the smallest positive integer that satisfies this is , so we have . Similarly, we have for some integer . Substituting into , we have . Apply this to the third expression we have and ,because . We find that is also a modular inverse of 15 by 7, and the smallest positive integer for this is 1, so . Again, we have for some integer , now substitute this into , we have . So we have . We can translate this easily into the following congruence: That is exactly the solution to the system of linear congruences.
In summary, back substitution works because multiplying both sides of a linear congruence by the modular multiplicative inverse of the coefficient allows us to isolate the variable and find its value modulo .
Fermat’s Little Theorem
This section discusses Fermat’s Little Theorem. This theorem is named after the French mathematician Pierre de Fermat, who first stated it in 1640. Fermat’s Little Theorem is a fundamental result in number theory and has numerous applications in cryptography, computer science, and other fields. It provides a way to reduce large powers modulo a prime number, which is essential for efficient computation in many algorithms.
Let be a prime number and be any integer not divisible by . Then, the following congruence relation holds: In other words, if we raise to the power of and divide the result by , the remainder is always .
In previous chapter, we introduced the fast modular exponential algorithm to calculate exponentiation modulo . Fermat’s Little Theorem provides another pathway that sometimes could even be faster.
Let be a prime number and be an integer not divisible by . Consider the set of integers and multiply each element by modulo . This operation permutes the set, as no two elements will have the same product modulo (if , then , which implies since is not divisible by ).
Therefore, the set is a permutation of modulo . Multiplying all elements in each set, we get: which can be rewritten as: Canceling the common factor (which is not divisible by ), we obtain: Thus, Fermat’s Little Theorem is proved.
To clarify the key points of this theorem, consider the following table. This table shows the case where p = 7 for . The row number represents , and column number represents , among the combination we see exactly the every six column gives a whole column that satisfies .
Compute using Fermat’s Little Theorem.
First, we check that the conditions for Fermat’s Little Theorem are satisfied:
-
is a prime number.
-
is not divisible by .
By Fermat’s Little Theorem, we know that: which can be rewritten as:
Now, we can use this result to simplify the calculation of :
Therefore, .
In this example, we first check that the conditions for Fermat’s Little Theorem are met: is a prime number, and is not divisible by . Then, we use Fermat’s Little Theorem to establish that .
To compute , we break down the exponent into smaller parts:
-
We write as .
-
Since , we can replace with , which is equal to .
-
We compute , which is .
-
Finally, we multiply and modulo to get the result: .
Use the Euclidean algorithm to find the greatest common divisor of 504 and 385. consider
-
Is it possible to find an integer such that ? If it is, find one. If it isn’t, explain why not.
-
Is it possible to find an integer such that ? If it is, find one. If it isn’t, explain why not.
By extended Euclidean Algorithm We conclude that
Since solving linear congruence is equivalent to solving Linear Diophantine Equation. So we need to solve The equation can be simplified to since . Because the gcd(119, 385) = 7 does divide 7, a solution exists. Dividing the equation by 7 gives . Testing multiples of 17 modulo 55, we find that , so is a solution.
For the second function, we cannot find any linear combination of integers for the expression, because .
For the general solution, we can use the conclusion obtained earlier in this chapter that where are just some integers, and are a set of specific solution, which could be found by back substitution. By back substitution in the lines of extended Euclidean algorithm, we have . So is the general solution for the equation.
Comments