Integers and Divisibility
Definitions
Basic objects we use in this course
Link copied-
Natural numbers: These are 0, 1, 2, 3, 4, 5,
The set of all natural numbers is denoted by .
We sometimes write or for the set of natural numbers that are .
-
Integers: These are , -3, -2, -1, 0, 1, 2, 3,
The set of all integers is denoted by .
-
Variables: We use symbols such as , , , , to denote integers whose values are variable or unknown; we call these integer variables.
Factors
Link copiedLet and be integers. Then we say that is a factor of (or a divisor of ), or that divides , if for some integer .
Prime numbers
Link copiedA prime number is a positive integer which has exactly two positive factors, namely and itself.
Rational numbers
Link copiedA rational number is any number that can be written in the form where and are integers and .
The integer is called the numerator and the integer is called the denominator of the rational number .
The set of all rational numbers is denoted by .
, , ( ), and are rational numbers.
Every integer is a rational number (because ).
Basic properties of integers
The following hold for all integers , and :
Associative laws:
Commutative laws:
Identity laws:
Distributive law:
Other properties:
Transitivity
Link copiedIf is a factor of , and is a factor of , then is a factor of .
Proof. If and for integers and , then , with .
Anti-symmetry
Link copiedLet be integers such that and : If is a factor of , and is a factor of , then .
Proof. Since is a factor of we have for some integer . Hence . Similarly, if is a factor of then . Thus and , which together imply that .
Notation and summary
Link copiedWe often write when is a factor of .
With this notation, we can summarise properties of the “factor” relation as follows. For all positive integers and :
Further exercises
Link copiedLet . Prove the following statements.
- for all .
- If and then .
- If and then .
- If then .
Is it true that if then either or ?
Warning: Do not confuse the statement (or relation) with the number .
Finding all factors of a positive integer
Let be a positive integer. How do we find all factors of ?
But first, why would we want to find all factors of ?
Secure data transmission (e.g. for internet banking) requires methods of encryption that are impervious to interception.
One of the principal methods (called the ‘RSA algorithm’) uses arithmetic based on integers expressible as product of two large prime numbers, and the difficulty of ‘cracking’ messages encrypted using this method relies on the difficulty of factorising large integers (with 300 digits or more). For more discussion see Section 8.4.
Algorithm for finding all factors of a positive integer
Link copiedFor any positive integer , let Factors denote the set of all (positive) factors of .
For example, Factors .
Question: Given , how do we find Factors ?
Simple algorithm - called FindFactors :
Given the positive integer as input,
- Initialise ;
- if then stop; otherwise if then output ;
- Increment by (i.e. ), then go to step 2.
Algorithm correctness
Link copiedAn algorithm is called correct if it terminates and satisfies its specification - that is, if it does what it is expected to do.
This algorithm terminates after steps, since is incremented at each iteration.
Correctness in this case means that the algorithm should find all factors of .
Proof of correctness of FindFactors :
- If is a factor of , then the algorithm outputs when step 2 is executed for the th time (that is, when ), and
- If is an output of the algorithm, then by step 2 it must be a factor of .
These two things ensure that is an output of the algorithm if and only if is a factor of , so the algorithm is correct.
Lemma 2.1 Let be any positive integer, and also suppose that . If is the smallest factor of with , then is prime.
For example, the smallest factor of is , which is prime.
Proof (by contradiction).
Let be the smallest factor of with . Suppose, for a contradiction, that is NOT prime. Then has some factor with . But now and , so , and therefore is a factor of smaller than , and with . This contradicts the definition of . Hence the supposition that was not prime is false, which completes the proof.
The Fundamental Theorem of Arithmetic
Link copiedThis theorem is fundamental to the study of integers: Every integer can be written as a product of prime numbers.
For example, and .
We will discuss this theorem again in Section 3.2. There are many ways to prove this. One of them is to prove the correctness of the following ‘constructive’ algorithm:
Given the integer as input,
- Initialise ;
- Find and output the smallest factor of with ;
- If then stop; otherwise replace by , and go to step 2.
Proof of correctness
Link copiedThe algorithm always terminates, since the value of decreases each time that step (3) is executed, unless .
Next, let the outputs of the algorithm be , and let be the corresponding values taken by .
By Lemma 2.1 each is prime, since it is the smallest factor of some integer greater than .
Also , and then , and so on, until , and then .
Thus
,
which gives as a product of the primes .
Take . Then the algorithm proceeds as follows:
- [initialisation];
- Output , and replace by ;
- Output , and replace by ;
- Output , and replace by ;
- Output , and stop [since ].
This algorithm gives .
Take . Then the algorithm proceeds as follows:
- [initialisation];
- Output , and replace by ;
- Output , and replace by ;
- Output , and replace by ;
- Output , and replace by ;
- Output , and replace by ;
- Output , and replace by ;
- Output , and stop [since ].
This algorithm gives .
Common divisors
Let and be positive integers.
A common divisor of and is any (positive) integer that divides both and .
The greatest common divisor of and is the largest integer that divides both and . It is denoted by .
The greatest common divisor is
Lemma 2.2 If is a common divisor of and , then divides for all integers and .
Proof. Since divides and , we know that and for integers and . It then follows that
and therefore divides .
As a corollary, also divides for all integers and (because we can simply replace by in the above proof).
Does make sense?
The Division Theorem (Quotient and Remainder)
Link copiedLet and be integers with . Then there exist integers and such that , with .
The integers and are called the quotient and remainder of on division by , respectively.
Note that the remainder has to be less than . Also note that is a factor of if and only if the remainder is zero.
Proof Consider all multiples of in increasing order, namely
Among these, find the largest multiple of with the property that , and then take .
Then (because ), and if then we have , and therefore .
But this shows there is a LARGER multiple of with , and so contradicts the choice of
Thus , and , as required.
The Euclidean algorithm
This is a fast algorithm for finding greatest common divisors. It was written down by Euclid in about 300BC, and re-discovered independently in India and China centuries later.
Euclidean algorithm
Link copiedLet the input be positive integers and .
The main idea of the algorithm is that if then
Termination of the algorithm is provided by the case .
We give the algorithm in detail:
-
If , then set and ; or if , then set and ; or if , then output as and stop;
-
Apply the division theorem to find integers and such that , with ;
-
If then output as and stop; otherwise re-set and then re-set , and go to step 2.
- and [initialisation]
- Find , and re-set and ;
- Find , and re-set and ;
- Find , output and stop [since ].
This algorithm gives .
Take and . Then proceed as follows:
- and [initialisation]
- Find , and re-set and ;
- Find , and re-set and ;
- Find , and re-set and ;
- Find , and re-set and ;
- Find , output and stop [since ].
This algorithm give .
Analysis of the Euclidean Algorithm
Link copiedFirst, we can observe that the values of and decrease each time that step (3) is executed, except when and it follows that the algorithm always terminates.
Now suppose the algorithm terminates after steps. We wish to show that the value output by the algorithm is the greatest common divisor of the integers and . The simplest way to show this is to write , where , and to note that the correctness of the algorithm follows from the correctness, at each iteration, of the statement
Lemma 2.3 Let be positive integers and let where . Then .
Proof. Consider the sets and . So is the set of common divisors of and , while is the set of common divisors of and . We will show that , and hence they have the same largest element.
So let . Then and and so by Lemma 2.2 we have that is a divisor of . Hence and and so . Conversely, suppose . Then and and so . So and . It follows that .
Extended Euclidean Algorithm
Link copiedThe extended Euclidean algorithm computes not only the integer , but also integers such that . These integers are interesting for some applications. These integers can also be computed by “reversing” the calculations in Euclid’s algorithm.
Recall the calculations from Example~2.7. Working backwards we have
.
Using the calculations from Example 2.8 find integers such that .
Congruences and modular arithmetic
Binary arithmetic
Link copiedThe set of integers can be partitioned into two subsets:
Even integers
Odd integers
These are the sets of integers that leave remainder or on division by , respectively, so we can label them as and .
We can write , , and , to indicate that
- if is even and is even then is even,
- if is even and is odd then is odd,
- if is odd and is even then is odd,
- if is odd and is odd then is even.
Similarly, we write , , and .
Integer congruence
Link copiedLet be any integer greater than .
We say that two integers and are congruent modulo , and write (mod ), if and leave the same remainder on division by .
(mod ), since both leave remainder on division by .
Similarly, (mod ) if and only if and are both even (leaving remainder on division by ) or both odd (leaving remainder on division by ).
Generally, (mod ) if and only if is a multiple of (leaving remainder on division by ).
What are the integers congruent to mod ?
These are , , , , , , , , , , .
Note that any two of these differ by a multiple of .
For example, , and .
In general, we have .
Theorem 2.1 (mod ) if and only if is a multiple of
Proof: Suppose that division by gives and , with remainders and (both less than ). Then we have
’Only if’ part: If (mod ), then by definition, , and so , which is a multiple of .
’If’ part: If is a multiple of , then so is
But and , so . Since the only multiple of strictly between and is , it follows that , so , and thus (mod ).
Properties of congruence mod
- (mod ) [reflexive]
- If (mod ) then (mod ) [symmetric]
- If (mod ) and (mod ) then (mod ) [transitive]
These are easy to prove from the definition of congruence mod (viz. leaving the same remainder on division by ).
Congruence classes
Link copiedLet be any integer greater than , and let be any integer.
By the division theorem, we have with . Then the set of all integers congruent to mod is the set of all integers leaving remainder on division by , namely
.
This set is called the congruence class of mod , and is denoted by .
Note that contains (since ). Also , and more generally, if and only if (mod ).
The number of congruence classes mod is
Let be any integer greater than . Then we know that for any integer , the congruence class consists of all integers leaving the same remainder as on division by , and in particular, , where .
It follows that every integer lies in exactly one of the congruence classes , , .
there are just two congruence classes mod , namely
even integers
odd integers.
Similarly, the ten congruence classes mod are
The ring of all congruence classes mod
Any integer contained in the congruence class is called a representative of the class.
The set of all congruence classes mod is denoted by . In other words,
.
Most books simply write .
When equipped with addition and multiplication, is an example of an algebraic structure known as a ‘ring’, called the ring of integers modulo , and if is a prime number, then is a field. Prime fields are very useful in constructing error-correcting codes, and in cryptography.
Some more exercises
Link copiedFix and let be such that and . Show that
- .
- .