Download presentation
Presentation is loading. Please wait.
Published byNeil Ball Modified over 8 years ago
1
Agenda Review: Relation Properties Lecture Content: Divisor and Prime Number Binary, Octal, Hexadecimal Review & Exercise
2
Review: Relation Properties
3
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}
4
Relation Properties Reflexive, Symmetric, Transitive: Antisymmetric Note: first, second, and third points need not be distinct
5
Example
6
Divisor and Prime Number
7
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.
8
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.
9
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.
10
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
11
Testing for Composite or Prime
12
Example
13
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
14
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.
15
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.
16
Greatest Common Divisor
17
Greatest Common Divisor: Example What is the greatest common divisor of 82320 and 950796? 82320 = 2 4. 3 1. 5 1. 7. 3. 11 0 950796 = 2 2. 3 2. 5 0. 7 4. 11 1 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.
18
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.
19
Least Common Multiple
20
Lcm and Gcd What is the least common multiple of 82320 and 950796? 82320 = 2 4. 3 1. 5 1. 7. 3. 11 0 950796 = 2 2. 3 2. 5 0. 7 4. 11 1 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 = 19015920. Theorem: For any positive integers m and n, gcd(m,n). Lcm(m,n) = mn
21
Representation of Integer
22
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.
23
Decimal 3854 = 3 * 10 3 + 8 * 10 2 + 5 * 10 1 + 4 * 10 0 = 3000 + 800 + 50 + 4 Base 10. Symbol: 0 - 9
24
Binary Base 2 Symbol: 0, 1 Binary to Decimal: 1110 = 1 * 2 3 + 1 * 2 2 + 1 * 2 1 + 0 * 2 0 = 8 + 4 + 2 + 0 = 14
25
Decimal to Binary N is an integer N = 1 * 2 k + b k-1 * 2 k-1 + … + b 0 * 2 0 130 ? 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 10000010
26
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
27
Binary Addition 10011011 + 1011011 = ? 11110110
28
Negative in Binary Two's complement: 1 0 0 1 Add 1 5 = 0000 0101 (Type data: byte) -5 = 1111 1010 + 1 = 1111 1011 Positive: Starting with 0 Negative: Starting with 1
29
Negative in Binary: 4 bits
30
Negative in Binary: 8 bits
31
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 2 + 4 * 16 1 + 15 * 16 0 = 11 * 256 + 4 * 16 + 15 * 1 = 2895
32
Decimal to Hexadecimal N is an integer N = 1 * 16 k + b k-1 * 16 k-1 + … + b 0 * 16 0 20385 ? 16) 20385 remainder 16) 1274 remainder 1 16) 79 remainder 10 16) 4 remainder 15 4 4FA1
33
Hexadecimal Addition 84F + 42EA = ? 4B39
34
Euclidean Algorithm
35
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).
36
Euclidean Algorithm
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.