Agenda Review: Relation Properties Lecture Content: Divisor and Prime Number Binary, Octal, Hexadecimal Review & Exercise
Review: Relation Properties
Relation: Definition Let A and B be sets. A binary relation from A to B is a subset of A B. Cartesian Product IF R : binary relation THEN a R b: (a, b) R a R b: (a, b) R Notation: domain: {a A | (a,b) R for some b B} range: {b B | (a,b) R for some a A}
Relation Properties Reflexive, Symmetric, Transitive: Antisymmetric Note: first, second, and third points need not be distinct
Example
Divisor and Prime Number
Divisors Definition: Let n and d be integers, d ≠ 0. We say that d divides n if there exists an integer q satisfying n = dq. We call q the quotient and d a divisor or factor of n. If d divides n, we write d | n. If d does not divide n, we write d | n. Example: Since 21 = 3·7, 3 divides 21 and we write 3 | 21. The quotient is 7. We call 3 a divisor or factor or 21. Show that if n and d are positive integers and d | n, then d ≤ n.
Divisors Note: Whether an integer d > 0 divides an integer n or not, we obtain a unique quotient q and remainder r as given by the Quotient-Remainder Theorem (See Lecture Week 3): There exist unique integers q (quotient) and r (remainder) satisfying n = dq+ r, 0 ≤ r < d The remainder r equals zero if and only if d divides n.
Divisors Theorem Let m, n, and d be integers. a)If d | m and d | n, then d | (m+ n). b)If d | m and d | n, then d | (m–n). c)If d | m, then d | mn.
Prime and Composite Definition An integer greater than 1 whose only positive divisors are itself and 1 is called prime. An integer greater than 1 that is not prime is called composite. Examples -Show that the integer 23 is prime. -Divisors: 1, 23 -Show that the integer 34 is composite. -Divisors: 1, 2, 17, 34
Testing for Composite or Prime
Example
If the input the earlier algorithm is n = 1274, the algorithm returns the prime 2 because 2 divides 1274, specifically 1274 = 2·637. If we input n = 637, we get the prime 7, specifically 637 = 7·91. With n = 91, we get the prime 7 again, specifically 91 = 7·13. If we now input n= 13, the algorithm returns 0 because 13 is prime. Combining the previous equations, we get 1274 = 2·7·7·13 note: product of Primes
Fundamental Theorem of Arithmetic Any integer greater than 1 can be written as a product of primes. Moreover, if the primes are written in nondecreasing order, the factorization is unique. In symbols, if n= p 1 p 2 ···p i, where the p k are primes and p 1 ≤p 2 ≤ ··· ≤ p i, and n= p’ 1 p’ 2 ···p’ j, where the p’ k are primes and p’ 1 ≤ p’ 2 ≤ ··· ≤ p’ j, then i = j and p k = p’ k for all k= 1,..., i.
Greatest Common Divisor Definition Let m and n be integers with not both m and n zero. A common divisor of m and n is an integer that divides both m and n. The greatest common divisor, written gcd(m,n), is the largest common divisor of m and n. Example What is the greatest common divisor of 30 and 105? We can find the answer by enumerating the positive divisors of each number. We can also find the answer by inspecting the prime factorization of each number.
Greatest Common Divisor
Greatest Common Divisor: Example What is the greatest common divisor of and ? = = gcd(82320,950796) = 2 min(4,2) · 3 min(1,2) ·5 min(1,0) ·7 min(3,4) ·11 min(0,1) = 2 2 ·3 1 ·5 0 ·7 3 ·11 0 = 4116.
Least Common Multiple Definition Let m and n be positive integers. A common multiple of m and n is an integer that is divisible by both m and n. The least common multiple, written lcm(m,n), is the smallest positive common multiple of m and n. Example The least common multiple of 30 and 105 Use the “list all divisors” method. Use the prime factorization method.
Least Common Multiple
Lcm and Gcd What is the least common multiple of and ? = = lcm(82320,950796) = 2 max(4,2) · 3 max(1,2) ·5 max(1,0) ·7 max(3,4) ·11 max(0,1) = 2 4 ·3 2 ·5 1 ·7 4 ·11 1 = Theorem: For any positive integers m and n, gcd(m,n). Lcm(m,n) = mn
Representation of Integer
Bits In computer data and instruction are encoded as bits. A bit is a binary digit, a 0 or a 1. -Binary number system: represents integer using bits. Other number system: -Decimal number system: represents integer using 10 symbols: 0,1,2,3,4,5,6,7,8,9 -Hexadecimal number system: represents integer using 16 symbols.
Decimal 3854 = 3 * * * * 10 0 = Base 10. Symbol: 0 - 9
Binary Base 2 Symbol: 0, 1 Binary to Decimal: 1110 = 1 * * * * 2 0 = = 14
Decimal to Binary N is an integer N = 1 * 2 k + b k-1 * 2 k-1 + … + b 0 * ? 2) 130 remainder 0 2) 65 remainder 1 2) 32 remainder 0 2) 16 remainder 0 2) 8 remainder 0 2) 4 remainder 0 2) 2 remainder 0 2) 1 remainder 1 0
Data type with number of bits Byte: 8 bits, range: -128 s/d +127 Short: 16 bits, -2 8 s/d 2 7 Integer: 32 bits Long: 64 bits Float: 32 bits Double: 64 bits
Binary Addition = ?
Negative in Binary Two's complement: 1 0 0 1 Add 1 5 = (Type data: byte) -5 = = Positive: Starting with 0 Negative: Starting with 1
Negative in Binary: 4 bits
Negative in Binary: 8 bits
Hexadecimal Base 16 Symbol 0 – 9, A, B, C, D, E, F 0 – 9, 10, 11, 12, 13, 14, 15 (Hexadecimal to Decimal) B4F = 11 * * * 16 0 = 11 * * * 1 = 2895
Decimal to Hexadecimal N is an integer N = 1 * 16 k + b k-1 * 16 k-1 + … + b 0 * ? 16) remainder 16) 1274 remainder 1 16) 79 remainder 10 16) 4 remainder 15 4 4FA1
Hexadecimal Addition 84F + 42EA = ? 4B39
Euclidean Algorithm
Efficient algorithm for finding the greatest common divisor of two integers. E.g. application: cryptosystem Based on Theorem: If a is a nonnegative integer, b is a positive integer, and r = a mod b, then gcd(a,b) = gcd(b,r).
Euclidean Algorithm