The Integers and Division

Download Report

Transcript The Integers and Division

The Integers and Division
Outline
•
•
•
•
•
•
•
•
Division: Factors, multiples
Exercise 2.3
Primes: The Fundamental Theorem of Arithmetic.
The Division Algorithm
Greatest Common Divisors: Relatively prime
Least Common Multiples
Modular Arithmetic: Congruence
Applications of Congruence: Cryptology
Division
• Definition Let a and b be integers with a0.
Then, we say that a divides b (and we note a | b) if there is
an integer c such that b = ac.
– a is called a factor of b, and b is multiple of a.
– We note a ¬| b when a does not divide b
• I used above notation for lack of strike vertical in PP.
– Examples 3 | 12, but 3 ¬| 14
– Note P(a, b): a | b is a predicate, with values True or False.
• Theorem Let a, b, c be integers with a  0. Then,
– if a | b and a | c, then a | (b+c);
– if a | b, then a | bc;
– if a | b and b | c, then a | c.
Exercise 2.3a
Primes
• Definition A positive integer p greater than 1 is called
prime if the only positive factors of p are 1 and p.
– A positive integer that is greater than 1 and is not prime is called
composite.
– Examples 7 is prime. 9 is composite.
– Note 1 is not prime, nor composite.
– Some primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47…
• The Fundamental Theorem of Arithmetic
Every positive integer can be written uniquely as the
product of primes, in increasing order.
– Examples. 100 = 22  52, 641 = 641, 999 = 33  37, and 1024 = 210.
Primes – Cont.
• Theorem If n is a composite integer, then n has a prime
divisor less than or equal to n.
• An integer n is prime if it is not divisible by any prime less
than or equal to n.
– 101 is prime, since 101 is not divisible by 2, 3, 5, or 7 (the only
primes less or equal than 101.)
• Prime factorization of 7007:
–
–
–
–
Divide 7007 by primes, starting with 2, 3, 7… 7007/7 = 1001.
Divide 1001 by primes, starting with 7… 1001/7 = 143.
Divide 143 by primes, starting with 7… 143/11 = 13.
Stop, since 13 is prime. 7007 = 72  11  13
The Division Algorithm
• The Division Algorithm 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.
–
–
–
–
–
d is called the divisor,
a is called the dividend,
q is called the quotient,
r is called the reminder.
Examples 101 = 11  9 + 2. How about: 101 = 11  8 + 13?
-11 = 3(-4) + 1. How about: -11 = 3(-3) - 2?
Greatest Common Divisors
• Definition Let a and b be integers, not both
zero. The largest integer d such that d | a
and d | b , denoted by gcd(a, b), is called the
greatest common divisor of a and b.
– Examples
gcd(24, 36) = 12.
gcd(17, 22) = 1.
Greatest Common Divisors -Cont
• Procedure to find gcd(a, b):
– Find the prime factorization of a and b.
a1
a2
an
b1
b2
bn
– If a = p1 p2 … pn , b = p1 p2 … pn , then
min(a1,b1)
min(a2,b2)
min(an,bn)
gcd(a, b) = p1
p2
… pn
– Examples
120 = 23  3  5 and 500 = 22  53 = 22  30  53
gcd(120, 500) = 22  30  51 = 20.
Relatively Prime Integers
• Definition The integers a and b are relatively
prime if gcd(a, b) = 1.
– Example 17 and 22 are relatively prime.
• Definition The integers a1, a2, …, an are pairwise
relatively prime if gcd(ai, aj)=1 whenever 1i<jn.
– Examples
10, 17 and 21 are pairwise relatively prime.
10, 17 and 24 are not pairwise relatively prime.
Least Common Multiples
• Definition Let a and b be positive integers. The
least common multiple of a and b is the smallest
positive integer that is divisible by both a and b.
It is denoted by lcm(a, b).
a
a
a
b
b
b
– If a = p1 1 p2 2… pn n, b = p1 1 p2 2… pn n, then
lcm(a, b) = p1max(a1,b1) p2max(a2,b2) … pnmax(an,bn)
– Example lcm(233572, 2433) = 243572.
• Theorem a + b +
ab = gcd(a, b)  lcm(a, b)
Modular Arithmetic
• Definition Let a be an integer and m a positive
integer. a mod m denotes the reminder when a is
divided by m.
– a mod m = r, where 0  r < m and a = qm + r.
– Examples
17 mod 5 = 2 (since 17 = 3  5 + 2.)
-133 mod 9 = 2
2001 mod 101 = 82
– The function fm: Z → {0, 1, 2, …, m-1}, where fm(a) = a mod m is
onto, but not one-to-one.
Congruence
• Definition If a and b are integers and m a positive
integer, then a is congruent to b modulo m (a  b
(mod m)) if m divides (a – b).
– Note a  b (mod m)  a mod m = b mod m
– Examples
17  5 (mod 6), since 17-5 = 12 = 6  2 is a multiple of 6.
Note also that 17 mod 6 = 5 mod 6 = 5.
24 ¬  14 (mod 6)
• I used above notation for lack of strike  in PP.
Congruence – Cont.
• Theorem mZ+ aZ bZ
ab (mod m)  kZ a = b + km
• Theorem
If ab (mod m) and cd (mod m), then:
a+c  b+d (mod m), and
ac  bd (mod m).
Applications of Congruence
• Hashing Functions
• Pseudorandom Numbers
– Linear congruential method
• Cryptology
– Caesar cipher
Hashing Functions
• Records are identified by a key (integer k).
– For example, using Social Security number
• To record k, assign memory location
– h(k) = k mod m, where m is the number of available
memory locations.
• h(k) is easily evaluated; it is also onto.
• Example. If m=111, the record with k=064212848 is assigned
to location 14 since h(064212848) = 064212848 mod 111 = 14.
• Collision may occur since h(k) is not one-to-one.
– Resolve by assigning next free location.
Pseudorandom Numbers
• Linear congruential method
– Choose: modulus m, multiplier a, increment c, and seed
x0, with 2  a < m, 0  c, x0 < m
– Generate the sequence {xn}
• xn+1 = (a xn + c) mod m.
– Example m = 9, a = 7, c = 4, and x0 = 3:
• x1 = 7x0+4 mod 9 = 7  3 + 4 mod 9 = 25 mod 9 = 7
• x2=8, x3=6, x4=1, x5=2, x6=0, x7=4, x8=5, x9=3.
– Usually, a pure multiplicative generator is used:
• Increment c=0, modulus m=231 – 1, multiplier a=75=16,807.
Cryptology
• Caesar’s encryption process:
– Represent each letter by an integer from 0 to 25
– Replace a letter represented by p by the letter
represented by f(p) = (p + 3) mod 26.
– Example
• M  12, f (12) = (12+3) mod 26 = 15  P
• “Meet you in the park’’ is replaced by “Phhw brx lq wkh sdun”
– Decryption. To recover the original message, use the
inverse function f -1(p)= (p - 3) mod 26.
Cryptology – Cont.
• Caesar cipher can be generalized:
– Shift cipher:
• f(p) = (p + k) mod 26.
– Affine transformation:
• f(p) = (ap + b) mod 26, where a and be are integers
chosen so that f is a bijection.
• Example f(p) = (7p + 3) mod 26, K?
– K  10, f (10) = (7  10 + 3) mod 26 = 73 mod 26 = 21  V.
– K is replaced by V in the encrypted message.