DS Lecture-10 Num TH
DS Lecture-10 Num TH
Overview of Lecture
Number theory (Chap 4)
• Divisibility & Modular Arithmetic
• Primes & Greatest Common Divisors
• The Sieve of Eratosthenes
• The Eucledian algorithm
SECTION 4.1 DIVISIBILITY AND
MODULAR ARITHMETIC
• Division
• Division algorithm
• Modular arithmetic
• Arithmatic modulo m
Number Theory
Study of the set of integers and their properties is known as number theory.
Division
Definition
1. If a and b are integers with a = 0, we say that a divides b if there is an integer c
such that b = ac, or equivalently, if is an integer.
2. When a divides b we say that a is a factor or divisor of b, and that b is a multiple
of a.
3. The notation a | b denotes that a divides b. We write a | b when a does not divide
b.
Basic Properties Of Divisibility
• Let a be an integer and d a positive integer. Then there are unique integers q and
r, with 0 ≤ r ≤ d such that
a = dq + r
• In the above division algorithm, d is called the divisor, a is called the dividend, q
is called the quotient, and r is called the remainder. This notation is used to
express the quotient and remainder:
q = a div d, r = a mod d.
Division Algorithm
• Example: What are the quotient and remainder when −11 is divided by 3?
Division Algorithm
• Example: What are the quotient and remainder when −11 is divided by 3?
• Solution: We have
−11 = 3(−4) + 1.
Hence, the quotient when −11 is divided by 3 is −4 = −11 div 3, and the remainder is 1 = −11 mod
3.
• Solution:
No. Because remainder cannot be negative. Consequently, the remainder is not −2, even though
−11 = 3(−3) − 2
because r = −2 does not satisfy 0 ≤ r < 3
Modular Arithmetic- Congruence
• We can define Arithmetic operations on Zm, the set of nonnegative integers less than m, that is, the set
a +m b = (a + b) mod m
a .m b = (a · b) mod m
• The operations +m and .m are called addition and multiplication modulo m and when we use these
operations, we are said to be doing arithmetic modulo m.
Arithmetic Modulo m
• Example: Use the definition of addition and multiplication in Zm to find 7 +11 9 and
7 .11 9.
• Solution:
Using the definition of addition modulo 11, we find that
7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5
4. What time does a 12-hour clock read a) 80 hours after it reads 11:00? b) 40 hours before it reads
12:00? c) 100 hours after it reads 6:00?
SECTION 4.3 PRIMES AND
GREATEST COMMON DIVISORS
• Primes
• Trial division
• The Sieve of Erstosthenes
• GCD
• Pairwise relatively prime
• The Eucledian algorithm
Primes
• A prime is an integer greater than 1 that is divisible by no positive integers other than 1
and itself.
• A positive integer that is greater than 1 and is not prime is called composite.
• Example:
The integer 7 is prime because its only positive factors are 1 and 7, whereas the integer 9
is composite because it is divisible by 3.
The Fundamental Theorem Of Arithmetic
• Every integer greater than 1 can be written uniquely as a prime or as the product of
two or more primes where the prime factors are written in order of non-decreasing
size.
• Example: The prime factorizations of 100, 641, 999, and 1024 are given by
100 = 2 · 2 · 5 · 5 = 22 52
641 = 641
999 = 3 · 3 · 3 · 37 = 33 · 37
1024 = 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 = 210
TRIAL DIVISION
It is a simple and efficient algorithm for finding all prime numbers up to a given limit. The
algorithm :
• Create a list of all numbers from 2 to the given limit.
• Start with the first number in the list (2) and mark it as prime.
• For each multiple of the current prime number (2), mark it as composite (i.e., not prime).
• Move to the next unmarked number in the list and repeat steps 2-3 until all numbers have been
processed.
• At the end of the algorithm, all unmarked numbers in the list are prime. This is because any
number that is composite (not prime) has already been marked as such by its prime factors.
Sieve Of Eratosthenes
Greatest Common Divisors
• The integers a and b are relatively prime if their greatest common divisor is 1.
• The integers a1, a2,...,an are pairwise relatively prime if gcd(ai, aj ) = 1
• Example: Determine whether the integers 10, 17, and 21 are pairwise relatively prime and
whether the integers 10, 19, and 24 are pairwise relatively prime.
• Solution:
Because gcd(10, 17) = 1, gcd(10, 21) = 1, and gcd(17, 21) = 1, we conclude that 10, 17, and
21 are pairwise relatively prime.
Because gcd(10, 24) = 2 > 1, we see that 10, 19, and 24 are not pairwise relatively prime.
GCD-Prime Factorization
• Another way to find the gcd of two positive integers is to use the prime
factorizations of these integers.
• Example: Because the prime factorizations of 120 and 500 are
120 = 2 · 2 · 2 · 3 · 5 and 500 = 2 · 2 · 5 · 5 · 5
the greatest common divisor is
gcd(120, 500) = 2min(3,2) 3min(1,0) 5min(1,3) = 22 30 51 = 20
GCD- Euclidean Algorithm
The Euclidean algorithm is a way to find the greatest common divisor of two
positive integers.
• Basic Euclidean Algorithm for GCD:
The algorithm is based on the below facts.
If we subtract a smaller number from a larger one (we reduce a larger number),
GCD doesn’t change. So if we keep subtracting repeatedly the larger of two, we
end up with GCD.
Now instead of subtraction, if we divide the smaller number, the algorithm
stops when we find the remainder 0.
Euclidean Algorithm
Find the greatest common divisor of 414 and 662 using the Euclidean algorithm.
Solution:
Successive uses of the division algorithm give:
662 = 414 · 1 + 248
414 = 248 · 1 + 166
248 = 166 · 1 + 82
166 = 82 · 2 + 2
82 = 2 · 41.
Hence, gcd(414, 662) = 2, because 2 is the last nonzero remainder
Activity
1. Determine whether each of these integers is prime.
a) 21 b) 29 c) 71 d) 97
2. Find the prime factorization of each of these integers.
b) 88 b) 126 c) 729
3. Determine whether the integers in each of these sets are pairwise relatively prime.
c) 11, 15, 19 b) 14, 15, 21 c) 12, 17, 31, 37 d) 7, 8, 9, 11
• Find gcd(1000, 625) and lcm(1000, 625) and verify that gcd(1000, 625) ⋅ lcm(1000, 625) = 1000
⋅ 625
Thank you