11 Integers and Division
11 Integers and Division
CS/APMA 202
Rosen section 2.4
Aaron Bloomfield
1
Rosen, chapter 2
We are only doing 2 or 3 of the sections in
chapter 2
Quick survey
a)
b)
c)
d)
If a | b and b | c, then a | c
Prime numbers
A positive integer p is prime if the only
positive factors of p are 1 and p
100 = 2 * 2 * 5 * 5
182 = 2 * 7 * 13
29820 = 2 * 2 * 3 * 5 * 7 * 71
Composite factors
If n is a composite integer, then n has a prime divisor less
than or equal to the square root of n
Direct proof
11
Proof by contradiction
Assume there are a finite number of primes
List them as follows: p1, p2 , pn.
Consider the number q = p1p2 pn + 1
Mersenne numbers
Mersenne nubmer: any number of the form 2n-1
Mersenne prime: any prime of the form 2p-1, where p is
also a prime
Merenne primes
Reference for Mersenne primes:
http://
mathworld.wolfram.com/MersennePrime.html
Finding Mersenne primes
ln (10200) 460
16
q = a div d
r = a mod d
18
Denoted by gcd(a,b)
Examples
Relative primes
Two numbers are relatively prime if they
dont have any common factors (other
than 1)
21
More on gcds
Given two numbers a and b, rewrite them
a
b
a
a
b
b
a
p
p
...
p
,
b
p
p
...
p
as:
1
2
n
1
2
n
1
Then
10*25 = 5*50
95256*432 = 216*190512
Modular arithmetic
If a and b are integers and m is a positive integer, then a is
congruent to b modulo m if m divides a-b
Notation: a b (mod m)
Rephrased: m | a-b
Rephrased: a mod m = b
Rephrased: 17 5 (mod 6)
Rephrased: 24 14 (mod 6)
As 6 does not divide 24-14 = 10, they are not congruent
25
More on congruence
Let a and b be integers, and let m be a positive
integer. Then a b (mod m) if and only if a mod
m = b mod m
Rephrased: 24 14 (mod 6)
24 mod 6 14 mod 6
26
17 = 5 + 2*6
5 = 17 -2*6
27
Example
Uses of congruences
Hashing functions
aaron@orion:~/ISOs/dvd.39> md5sum debian-31-i386-binary.iso
96c8bba5a784c2f48137c22e99cd5491 debian-31-i386-binary.iso
29
Todays demotivators
30
Pseudorandom numbers
Computers
numbers!
cannot
generate
truly
random
Pseudorandom numbers
Formula: xn+1 = (axn + c) mod m
Let x0 = 3, m = 9, a = 7, and c = 4
x1 = 7x0+4 = 7*3+4 = 25 mod 9 = 7
x2 = 7x1+4 = 7*7+4 = 53 mod 9 = 8
x3 = 7x2+4 = 7*8+4 = 60 mod 9 = 6
x4 = 7x3+4 = 7*6+4 = 46 mod 9 = 1
x5 = 7x4+4 = 7*1+4 = 46 mod 9 = 2
x6 = 7x5+4 = 7*2+4 = 46 mod 9 = 0
x7 = 7x6+4 = 7*0+4 = 46 mod 9 = 4
x8 = 7x7+4 = 7*4+4 = 46 mod 9 = 5
32
Pseudorandom numbers
Formula: xn+1 = (axn + c) mod m
Let x0 = 3, m = 9, a = 7, and c = 4
This sequence generates:
3, 7, 8, 6, 1, 2, 0, 4, 5, 3 , 7, 8, 6, 1, 2, 0, 4, 5, 3
Decrypt jr wfdydolhuv
Rot13 encoding
A Caesar cipher, but translates letters by 13
instead of 3
Quick survey
a)
b)
c)
d)
37
Quick survey
a)
b)
c)
d)
38
Quick survey
a)
b)
c)
d)
39