Number Theory
Learn the basics of number theory, that is, divisibility, GCD, prime, and relatively prime numbers, in this lesson.
We'll cover the following
Basics of number theory
In this section, we’ll introduce the basic concepts of number theory, which are later used to determine the properties of algebraic structures. We denote the set of integers by the symbol
. The following statements hold for the usual addition, subtraction, and multiplication:
Lemma 1: closure property
Let a, b ∈ .
Then, the following hold:
This means that the common addition, subtraction, and multiplication operations yield an integer as a result. We say that the set of integers is closed under these operations (we’ll learn this concept in detail in the next lessons).
In contrast, the division of two integers a and b isn’t necessarily yielding an integer as a result, thus, the integers aren’t closed with respect to the division. For example, we can’t divide by because . As a consequence, we need a fundamental concept of divisibility in number theory.
Divisibility
Let a,b ∈ Z with b ≠ 0. We say that divides , or is divisible by , if there exists an ∈ Z such that:
If b divides a, we write , otherwise, we write .
Example: It holds that , since . On the other hand, .
The following lemma states some elementary divisibility properties.
Lemma 2: properties of divisibility
Let ⧵{0}.
Then:
- If , then , and vice versa.
- Transitive property: If and , then .
- If and , then and .
Proof:
- Since , there exists an such that . It follows that and hence . For the reverse direction, we observe that requires an so that . Since , it follows that and hence .
- and imply that there exist so that we can write and , respectively. It follows that , and thus .
- and imply the existence of so that and This yields and hence .
# isDivisible : returns 1, if a divides b (a|b)# parameters a and bdef isDivisible(a, b):if b%a == 0:return 1else:return 0# Feel free to change value of a and ba = 13b = 39print(a , " | ", b, " = ", 'true' if isDivisible(a,b)== 1 else 'false' )
Greatest common divisor
A positive integer is called a common divisor of two integers and , if divides both of them. The greatest common divisor of a and b is the largest integer such that and and is denoted by .
Note: Especially, and .
Example: since and , and there’s no larger number than , which fulfils this property.
# GCD : Returns the GCD of a and b# Parameters a and bdef GCD(a, b):if (a == 0):return belif (a == 1):return 1else:return GCD(b%a, a)# Feel free to change value of a and ba = 48b = 72if (a > b):print("invalid input, a must be <= to b")else:print("GCD of ", a, " and ", b ," = ", GCD(a,b))
Prime numbers:
Let be a positive integer . Then, is said to be a prime if its only divisors are and itself, i.e.,
for all .
Note: is a prime number because 1 can be divided by 1 and the number itself, which is also 1.
Example:
All the primes smaller than are . For example, is not a prime since , and hence, and are divisors of .
Theorem 1: fundamental theorem of arithmetic
Every positive integer can be represented as a product of prime powers
This factorization is unique apart from the rearrangement of the prime powers.
Note: The greatest common divisor of two numbers and can be computed by determining their prime factorizations, whereas the greatest common divisor is the product of all common prime powers of and . This is depicted in the above figure using the prime factorization tree.
Example:
Consider the two numbers and . Their prime factorizations are given by and . We observe that a and b have common prime powers and , and therefore .
Theorem 2: there are infinitely many primes
Proof:
Suppose that there’s a complete finite list of primes . We construct the two integers and . By the fundamental theorem of arithmetic, every integer is a product of primes divisible by at least one prime. Since is a product of all primes, there’s a prime such that and . According to Lemma 2: properties of divisibility, and imply that . Hence, , which means that divides 1. But this isn’t possible since is a prime, and therefore . Thus, a list of finite primes can’t exist as will not be a member of it.
Relatively prime (or coprime)
Two integers and are said to be relatively prime (or coprime) if .
Example:
We consider the following two cases:
- and are relatively prime, since and . Thus, they have no common prime factors, and therefore .
- and are not relatively prime, since and , and therefore .
Lemma 3: Bézout’s identity
For any nonzero integers , let d be the greatest common divisor . Then, there exist such that
Corollary 1
Two integers are co-prime if and only if there exist such that
Proof:
Two integers are relatively prime if and only if . Then, it’s a direct consequence of Bézout’s lemma that there exists such that .
Lemma 4
Let and . If and are coprime to , then it’s also its product , i.e., if , then .
Proof:
Suppose that . As discussed earlier , there exist such that and , and thus, in total
It follows that
Here, and .
By applying again the corollary discussed earlier, we conclude that .
Lemma 5
Let , and let . Then, the two integers and are relatively prime, i.e., .
Proof:
According to the fundamental theorem of arithmetic , we define and as a product of prime powers, i.e., and . Then, , whereas are the common prime powers of and . As a consequence, the two integers and have no common prime powers, and hence .
# GCD : returns returns GCD of a and b.# parameters a and bdef GCD(a, b):if (a == 0):return belif (a == 1):return 1else:return GCD(b%a, a)# isCoPrime : returns 1 when a and b are coprime to each other,# otherwise returns 0# parameters a and bdef isCoPrime(a, b):if (a > b):return 1 if GCD(b, a)==1 else 0else:return 1 if GCD(a, b)==1 else 0# Feel free to change value of a and ba = 18b = 5print(a," is ", 'coprime' if isCoPrime(a, b)==1 else 'not coprime' , " to ", b);