DS Chapter 04
DS Chapter 04
Chapter 4
Number Theory and Cryptography
• if a | b and a | c, then a | (b + c)
Example: 3 | 6 and 3 | 9, so 3 | 15.
• if a | b and b | c, then a | c
Example: 4 | 8 and 8 | 24, so 4 | 24.
Examples:
9 mod 4 = 1
9 mod 3 = 0
9 mod 10 = 9
-13 mod 4 = 3
Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
1 11 carry
Example: 7583
+ 4932
12515
1 1 carry
Binary expansions: (1011)2
+ (1010)2
( 1 0 1 0 1 )2
Therefore, s = a + b = (11001)2.
01/31/24 Discrete Mathematics Chapter 4 31
Addition of Integers
procedure add(a, b: positive integers)
c := 0
for j := 0 to n-1
begin
d := (aj + bj + c)/2
sj := aj + bj + c – 2d
c := d
end
sn := c
{the binary expansion of the sum is (snsn-1…s1s0)2}
48 = 2·2·2·2·3 = 24·3
17 = 17
100 = 2·2·5·5 = 22·52
512 = 2·2·2·2·2·2·2·2·2 = 29
515 = 5·103
28 = 2·2·7
a = p 1 a1 p 2 a2 … p n an , b = p 1 b 1 p 2 b 2 … p n b n ,
where p1 < p2 < … < pn and ai, bi N for 1 i n
Example:
a = 60 = 22 31 51
b = 54 = 21 33 50
gcd(a, b) = 21 31 50 = 6
Examples:
Are 15 and 28 relatively prime?
Yes, gcd(15, 28) = 1.
Are 55 and 28 relatively prime?
Yes, gcd(55, 28) = 1.
Are 35 and 28 relatively prime?
No, gcd(35, 28) = 7.
01/31/24 Discrete Mathematics Chapter 4 42
Relatively Prime Integers
Definition:
The integers a1, a2, …, an are pairwise relatively
prime if gcd(ai, aj) = 1 whenever 1 i < j n.
Examples:
Are 15, 17, and 27 pairwise relatively prime?
No, because gcd(15, 27) = 3.
Are 15, 17, and 28 pairwise relatively prime?
Yes, because gcd(15, 17) = 1, gcd(15, 28) = 1 and
gcd(17, 28) = 1.
01/31/24 Discrete Mathematics Chapter 4 43
Least Common Multiples
Definition:
The least common multiple of the positive integers a
and b is the smallest positive integer that is divisible by
both a and b.
We denote the least common multiple of a and b by
lcm(a, b).
Examples:
lcm(3, 7) = 21
lcm(4, 6) = 12
lcm(5, 10) = 10
01/31/24 Discrete Mathematics Chapter 4 44
Least Common Multiples
Using prime factorizations:
a = p 1 a1 p 2 a2 … p n an , b = p 1 b 1 p 2 b 2 … p n b n ,
where p1 < p2 < … < pn and ai, bi N for 1 i n
Example:
a = 60 = 22 31 51
b = 54 = 21 33 50
lcm(a, b) = 22 33 51 = 4.27.5 = 540
a = 60 = 22 31 51
b = 54 = 21 33 50
gcd(a, b) = 21 31 50 =6
lcm(a, b) = 22 33 51 = 540
So we divide 14 by 7:
14 = 72 + 0
We find that 7 | 14, and thus gcd(14, 7) = 7.