0% found this document useful (0 votes)
119 views51 pages

Number Theory: Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry

The document discusses number theory concepts like division, primes, and the Sieve of Eratosthenes algorithm for determining if a number is prime or composite. It defines prime numbers as integers greater than 1 that are only divisible by 1 and themselves. The Sieve of Eratosthenes algorithm checks if a given number n is divisible by all prime numbers up to the square root of n; if any division is exact, then n is composite, otherwise it is prime. While simple, this algorithm is very inefficient due to the large number of iterations required.

Uploaded by

Misbah Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views51 pages

Number Theory: Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry

The document discusses number theory concepts like division, primes, and the Sieve of Eratosthenes algorithm for determining if a number is prime or composite. It defines prime numbers as integers greater than 1 that are only divisible by 1 and themselves. The Sieve of Eratosthenes algorithm checks if a given number n is divisible by all prime numbers up to the square root of n; if any division is exact, then n is composite, otherwise it is prime. While simple, this algorithm is very inefficient due to the large number of iterations required.

Uploaded by

Misbah Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Number

Theory

CSE235 Number Theory


Division

Primes

Division
Slides by Christopher M. Bourke
Modular
Arithmetic Instructor: Berthe Y. Choueiry

Fall 2007

Computer Science & Engineering 235


Introduction to Discrete Mathematics
1 / 30
Sections 3.4–3.6 of Rosen
Introduction I

Number
Theory
When talking about division over the integers, we mean
CSE235
division with no remainder.
Division

Primes
Definition
Division Let a, b ∈ Z, a 6= 0, we say that a divides b if there exists c ∈ Z
Modular such that b = ac. We denote this, a | b and a - b when a does
Arithmetic
not divide b. When a | b, we say a is a factor of b.

Theorem
Let a, b, c ∈ Z then
1 If a | b and a | c then a | (b + c).
2 If a | b, then a | bc for all c ∈ Z.
3 If a | b and b | c, then a | c.

2 / 30
Introduction II

Number
Theory

CSE235

Division

Primes

Division Corollary
Modular
Arithmetic If a, b, c ∈ Z such that a | b and a | c then a | mb + nc for
n, m ∈ Z.

3 / 30
Division Algorithm I

Number
Theory

CSE235 Let a be an integer and d be a positive integer. Then there are


Division
unique integers q and r, with:
Primes

Division
0≤r≤d
Modular such that a = dq + r
Arithmetic

Not really an algorithm (traditional name). Further:

a is called the divident


d is called the divisor
q is called the quotient
r is called the remainder, and is positive.

4 / 30
Primes I

Number
Theory

CSE235

Division

Primes
Sieve
Distribution Definition
Interesting Items

Division
A positive integer p > 1 is called prime if its only positive
Modular
factors are 1 and p.
Arithmetic
If a positive integer is not prime, it is called composite.

5 / 30
Primes II

Number
Theory

CSE235
Theorem (Fundamental Theorem of Arithmetic, FTA)
Division

Primes
Every positive integer n > 1 can be written uniquely as a prime
Sieve or as the product of the powers of two or more primes written
Distribution
Interesting Items in nondecreasing size.
Division

Modular
Arithmetic That is, for every n ∈ Z, n > 1, can be written as

n = p1 k 1 p2 k 2 · · · pl k l

where each pi is a prime and each ki ≥ 1 is a positive integer.

6 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory

CSE235

Division Given a positive integer, n > 1, how can we determine if n is


Primes
Sieve
prime or not?
Distribution
Interesting Items
For hundreds of years, people have developed various tests and
Division
algorithms for primality testing. We’ll look at the oldest (and
Modular
Arithmetic most inefficient) of these.

Lemma

If n is a composite integer, then n has a prime divisor x ≤ n.

7 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory
Proof.
CSE235

Division

Primes
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

8 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory
Proof.
CSE235
Let n be a composite integer.
Division

Primes
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

8 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory
Proof.
CSE235
Let n be a composite integer.
Division
By definition, n has a prime divisor a with 1 < a < n, thus
Primes
Sieve n = ab.
Distribution
Interesting Items

Division

Modular
Arithmetic

8 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory
Proof.
CSE235
Let n be a composite integer.
Division
By definition, n has a prime divisor a with 1 < a < n, thus
Primes
Sieve n = ab.
Distribution √ √
Interesting Items
Its easy to see that either a ≤ n or b ≤ n. Otherwise,
Division √ √
if on the contrary, a > n and b > n, then
Modular
Arithmetic √ √
ab > n n = n

8 / 30
Sieve of Eratosthenes
Preliminaries

Number
Theory
Proof.
CSE235
Let n be a composite integer.
Division
By definition, n has a prime divisor a with 1 < a < n, thus
Primes
Sieve n = ab.
Distribution √ √
Interesting Items
Its easy to see that either a ≤ n or b ≤ n. Otherwise,
Division √ √
if on the contrary, a > n and b > n, then
Modular
Arithmetic √ √
ab > n n = n

Finally, either a or b is prime divisor or has a factor that is


a prime divisor by the Fundamental Theorem of

Arithmetic, thus n has a prime divisor x ≤ n.

8 / 30
Sieve of Eratosthenes
Algorithm

Number
Theory
This result gives us an obvious algorithm. To determine if a
number n is prime, we simple must test every prime number p
CSE235 √
with 2 ≤ p ≤ n.
Division

Primes
Sieve
Sieve
Distribution Input : A positive integer n ≥ 4.
Interesting Items
Output : true if n is prime.
Division √
1 foreach prime number p, 2 ≤ p ≤ n do
Modular 2 if p | n then
Arithmetic
3 output false
4 end
5 end
6 output true

q
n
Can be improved by reducing the upper bound to p at each
9 / 30 iteration.
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution √
Interesting Items
The outer for-loop runs for every prime p ≤ n.
Division

Modular
Arithmetic

10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution √
Interesting Items
The outer for-loop runs for every prime p ≤ n.
Division
Assume that we get such a list for free. The loop still
Modular
Arithmetic executes about √
n

ln n
times (see distribution of primes: next topic, also Theorem
4, page 213).

10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution √
Interesting Items
The outer for-loop runs for every prime p ≤ n.
Division
Assume that we get such a list for free. The loop still
Modular
Arithmetic executes about √
n

ln n
times (see distribution of primes: next topic, also Theorem
4, page 213).
Assume also that division is our elementary operation.

10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution √
Interesting Items
The outer for-loop runs for every prime p ≤ n.
Division
Assume that we get such a list for free. The loop still
Modular
Arithmetic executes about √
n

ln n
times (see distribution of primes: next topic, also Theorem
4, page 213).
Assume also that division is our elementary operation.

Then the algorithm is O( n).
10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory
This procedure, called the Sieve of Eratosthenes, is quite old,
CSE235
but works.
Division In addition, it is very inefficient. At first glance, this may seem
Primes counter intuitive.
Sieve
Distribution √
Interesting Items
The outer for-loop runs for every prime p ≤ n.
Division
Assume that we get such a list for free. The loop still
Modular
Arithmetic executes about √
n

ln n
times (see distribution of primes: next topic, also Theorem
4, page 213).
Assume also that division is our elementary operation.

Then the algorithm is O( n).
However, what is the actual input size?
10 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory

CSE235 Recall that it is log (n). Thus, the algorithm runs in


Division exponential time with respect to the input size.
Primes
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

11 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory

CSE235 Recall that it is log (n). Thus, the algorithm runs in


Division exponential time with respect to the input size.
Primes To see this, let k = log (n)
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

11 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory

CSE235 Recall that it is log (n). Thus, the algorithm runs in


Division exponential time with respect to the input size.
Primes To see this, let k = log (n)
Sieve
Distribution
Interesting Items
Then 2k = n and so
Division √ √
Modular n= 2k = 2k/2
Arithmetic

11 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory

CSE235 Recall that it is log (n). Thus, the algorithm runs in


Division exponential time with respect to the input size.
Primes To see this, let k = log (n)
Sieve
Distribution
Interesting Items
Then 2k = n and so
Division √ √
Modular n= 2k = 2k/2
Arithmetic

Thus the Sieve is exponential in the input size k.

11 / 30
Sieve of Eratosthenes
Efficiency?

Number
Theory

CSE235 Recall that it is log (n). Thus, the algorithm runs in


Division exponential time with respect to the input size.
Primes To see this, let k = log (n)
Sieve
Distribution
Interesting Items
Then 2k = n and so
Division √ √
Modular n= 2k = 2k/2
Arithmetic

Thus the Sieve is exponential in the input size k.

The Sieve also gives an algorithm for determining the prime


factorization of an integer. To date, no one has been able to
produce an algorithm that runs in sub-exponential time. The
hardness of this problem is the basis of public-key cryptography.

11 / 30
Sieve of Eratosthenes I
Primality Testing

Number
Theory

CSE235

Division
Numerous algorithms for primality testing have been developed
Primes
over the last 50 years.
Sieve
Distribution
Interesting Items
In 2002, three Indian computer scientists developed the first
Division deterministic polynomial-time algorithm for primality testing,
Modular running in time O(log12 (n)).
Arithmetic
M. Agrawal and N. Kayal and N. Saxena. Primes is in P.
Annals of Mathematics, 160(2):781-793, 2004.
Available at http://projecteuclid.org/Dienst/UI/1.0/
Summarize/euclid.annm/1111770735

12 / 30
How Many Primes?

Number
Theory

CSE235

Division

Primes
Sieve How many primes are there?
Distribution
Interesting Items

Division
Theorem
Modular There are infinitely many prime numbers.
Arithmetic

The proof is a simple proof by contradiction.

13 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235

Division

Primes
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

14 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235
Assume to the contrary that there are a finite number of
primes, p1 , p2 , . . . , pn .
Division

Primes
Sieve
Distribution
Interesting Items

Division

Modular
Arithmetic

14 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235
Assume to the contrary that there are a finite number of
primes, p1 , p2 , . . . , pn .
Division
Let
Primes
Sieve Q = p1 p2 · · · pn + 1
Distribution
Interesting Items

Division

Modular
Arithmetic

14 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235
Assume to the contrary that there are a finite number of
primes, p1 , p2 , . . . , pn .
Division
Let
Primes
Sieve Q = p1 p2 · · · pn + 1
Distribution
Interesting Items

Division
By the FTA, Q is either prime (in which case we are done)
Modular
or Q can be written as the product of two or more primes.
Arithmetic

14 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235
Assume to the contrary that there are a finite number of
primes, p1 , p2 , . . . , pn .
Division
Let
Primes
Sieve Q = p1 p2 · · · pn + 1
Distribution
Interesting Items

Division
By the FTA, Q is either prime (in which case we are done)
Modular
or Q can be written as the product of two or more primes.
Arithmetic
Thus, one of the primes pj (1 ≤ j ≤ n) must divide Q,
but then if pj | Q, it must be the case that

pj | Q − p1 p2 · · · pn = 1

14 / 30
How Many Primes?
Proof

Number Proof.
Theory

CSE235
Assume to the contrary that there are a finite number of
primes, p1 , p2 , . . . , pn .
Division
Let
Primes
Sieve Q = p1 p2 · · · pn + 1
Distribution
Interesting Items

Division
By the FTA, Q is either prime (in which case we are done)
Modular
or Q can be written as the product of two or more primes.
Arithmetic
Thus, one of the primes pj (1 ≤ j ≤ n) must divide Q,
but then if pj | Q, it must be the case that

pj | Q − p1 p2 · · · pn = 1

Since this is not possible, we’ve reached a


contradiction—there are not finitely many primes.

14 / 30
Distribution of Prime Numbers

Number
Theory

CSE235

Division Theorem
Primes The ratio of the number of prime numbers not exceeding n and
Sieve
n
Distribution
Interesting Items
ln n approaches 1 as n → ∞.
Division

Modular
Arithmetic
In other words, for a fixed natural number, n, the number of
primes not greater than n is about
n
ln n

15 / 30
Mersenne Primes I

Number
Theory

CSE235

Division
A Mersenne prime is a prime number of the form
Primes
Sieve
Distribution
Interesting Items 2k − 1
Division

Modular where k is a positive integer. They are related to perfect


numbers (if Mn is a Mersenne prime, Mn (M2 n +1) is perfect).
Arithmetic

Perfect numbers are numbers that are equal to the sum of their
proper factors, for example 6 = 1 · 2 · 3 = 1 + 2 + 3 is perfect.

16 / 30
Mersenne Primes II

Number
Theory

CSE235

Division It is an open question as to whether or not there exist odd


Primes perfect numbers. It is also an open question whether or not
Sieve
Distribution
Interesting Items
there exist an infinite number of Mersenne primes.
Division
Such primes are useful in testing suites (i.e., benchmarks) for
Modular
Arithmetic large super computers.
To date, 42 Mersenne primes have been found. The last was
found on February 18th, 2005 and contains 7,816,230 digits.

17 / 30
Division

Number Theorem (The Division “Algorithm”)


Theory

CSE235 Let a ∈ Z and d ∈ Z+ then there exists unique integers q, r


with 0 ≤ r < d such that
Division

Primes
a = dq + r
Division
gcd,lcm

Modular
Arithmetic
Some terminology:
d is called the divisor.
a is called the dividend.
q is called the quotient.
r is called the remainder.
We use the following notation:
q = a div d
r = a mod d
18 / 30
Greatest Common Divisor I

Number
Theory

CSE235 Definition
Division Let a and b be integers not both zero. The largest integer d
Primes such that d | a and d | b is called the greatest common divisor
Division of a and b. It is denoted
gcd,lcm

Modular
Arithmetic gcd(a, b)

The gcd is always guaranteed to exist since the set of common


divisors is finite. Recall that 1 is a divisor of any integer. Also,
gcd(a, a) = a, thus

1 ≤ gcd(a, b) ≤ min{a, b}

19 / 30
Greatest Common Divisor II

Number
Theory

CSE235 Definition
Division
Two integers a, b are called relatively prime if
Primes

Division
gcd(a, b) = 1
gcd,lcm

Modular
Arithmetic Sometimes, such integers are called coprime.
There is natural generalization to a set of integers.

Definition
Integers a1 , a2 , . . . , an are pairwise relatively prime if
gcd(ai , aj ) = 1 for i 6= j.

20 / 30
Greatest Common Divisor
Computing

Number
Theory
The gcd can “easily”1 be found by finding the prime
CSE235
factorization of two numbers.
Division

Primes
Let
Division
gcd,lcm a = p1 a 1 p2 a 2 · · · pn a n
Modular
Arithmetic b = p1 b1 p2 b2 · · · pn bn

Where each power is a nonnegative integer (if a prime is not a


divisor, then the power is 0).
Then the gcd is simply
min{a1 ,b1 } min{a2 ,b2 }
gcd(a, b) = p1 p2 · · · pnmin{an ,bn }

1
21 / 30 Easy conceptually, not computationally
Greatest Common Divisor
Examples

Number
Theory
Example
CSE235
What is the gcd(6600, 12740)?
Division
The prime decompositions are
Primes

Division
gcd,lcm
6600 = 23 31 52 70 111 130
Modular
Arithmetic
12740 = 22 30 51 72 110 131

So we have

gcd(6600, 12740) = 2min{2,3} 3min{0,1} 5min{1,2} 7min{0,2}


11min{0,1} 13min{0,1}
= 22 30 51 70 110 130
= 20

22 / 30
Least Common Multiple

Number
Theory

CSE235 Definition
Division The least common multiple of positive integers a, b is the
Primes smallest positive integer that is divisible by both a and b. It is
Division denoted
gcd,lcm
lcm(a, b)
Modular
Arithmetic

Again, the lcm has an “easy” method to compute. We still use


the prime decomposition, but use the max rather than the min
of powers.

max{a1 ,b1 } max{a2 ,b2 } n ,bn }


lcm(a, b) = p1 p2 · · · pmax{a
n

23 / 30
Least Common Multiple
Example

Number
Theory
Example
CSE235
What is the lcm(6600, 12740)?
Division
Again, the prime decompositions are
Primes

Division
gcd,lcm
6600 = 23 31 52 70 111 130
Modular 12740 = 22 30 51 72 110 131
Arithmetic

So we have

lcm(6600, 12740) = 2max{2,3} 3max{0,1} 5max{1,2} 7max{0,2}


11max{0,1} 13max{0,1}
= 23 31 52 72 111 131
= 4, 204, 200

24 / 30
Intimate Connection

Number
Theory

CSE235

Division

Primes
There is a very close connection between the gcd and lcm.
Division
gcd,lcm Theorem
Modular
Arithmetic
Let a, b ∈ Z+ , then

ab = gcd(a, b) · lcm(a, b)

Proof?

25 / 30
Congruences
Definition

Number
Theory

CSE235
Often, rather than the quotient, we are only interested in the
Division
remainder of a division operation. We introduced the notation
Primes
before, but we formally define it here.
Division

Modular
Arithmetic
Definition
Properties
Inverses
Let a, b ∈ Z and m ∈ Z+ . Then a is congruent to b modulo m
if m divides a − b. We use the notation

a ≡ b(mod m)

If the congruence does not hold, we write a 6≡ b(mod m)

26 / 30
Congruences
Another Characterization

Number
Theory

CSE235

Division An equivalent characterization can be given as follows.


Primes

Division
Theorem
Modular Let m ∈ Z+ . Then a ≡ b(mod m) if and only if there exists
Arithmetic
Properties q ∈ Z such that
Inverses
a = qm + b
i.e. a quotient q.

Alert: a, b ∈ Z, i.e. can be negative or positive.

27 / 30
Congruences
Properties

Number
Theory

CSE235 Theorem
Division Let a, b ∈ Z, m ∈ Z+ . Then,
Primes

Division a ≡ b(mod m) ⇐⇒ a mod m = b mod m


Modular
Arithmetic
Properties Theorem
Inverses
Let m ∈ Z+ . If a ≡ b(mod m) and c ≡ d(mod m) then

a + c ≡ b + d(mod m)

and
ac ≡ bd(mod m)

28 / 30
Modular Arithmetic
Example

Number
Theory

CSE235

Division Example
Primes 36
36 ≡ 1(mod 5) since the remainder of 5 is 1.
Division

Modular
Arithmetic
Properties
Inverses

29 / 30
Modular Arithmetic
Example

Number
Theory

CSE235

Division Example
Primes 36
36 ≡ 1(mod 5) since the remainder of 5 is 1.
Division

Modular
Similarly, −17 ≡ −1(mod 2), −17 ≡ 1(mod 2),
Arithmetic −17 ≡ 3(mod 2), etc.
Properties
Inverses

29 / 30
Modular Arithmetic
Example

Number
Theory

CSE235

Division Example
Primes 36
36 ≡ 1(mod 5) since the remainder of 5 is 1.
Division

Modular
Similarly, −17 ≡ −1(mod 2), −17 ≡ 1(mod 2),
Arithmetic −17 ≡ 3(mod 2), etc.
Properties
Inverses
However, we prefer to express congruences with
0 ≤ b < m.

29 / 30
Modular Arithmetic
Example

Number
Theory

CSE235

Division Example
Primes 36
36 ≡ 1(mod 5) since the remainder of 5 is 1.
Division

Modular
Similarly, −17 ≡ −1(mod 2), −17 ≡ 1(mod 2),
Arithmetic −17 ≡ 3(mod 2), etc.
Properties
Inverses
However, we prefer to express congruences with
0 ≤ b < m.
64 ≡ 0(mod 2), 64 ≡ 1(mod 3), 64 ≡ 4(mod 5),
64 ≡ 4(mod 6), 64 ≡ 1(mod 7), etc.

29 / 30
Inverses I

Number
Theory

CSE235
Definition
Division
An inverse of an element x modulo m is an integer x−1 such
Primes
that
Division xx−1 ≡ 1(mod m)
Modular
Arithmetic
Properties Inverses do not always exist, take x = 5, m = 10 for example.
Inverses

The following is a necessary and sufficient condition for an


inverse to exist.
Theorem
Let a and m be integers, m > 1. A (unique) inverse of a
modulo m exists if and only if a and m are relatively prime.

30 / 30

You might also like