Presentation is loading. Please wait.

Presentation is loading. Please wait.

AF2. Turn off your phones Primes, gcd, some examples, reading.

Similar presentations


Presentation on theme: "AF2. Turn off your phones Primes, gcd, some examples, reading."— Presentation transcript:

1 AF2

2 Turn off your phones

3 Primes, gcd, some examples, reading

4 Primes p>1 is prime if the only positive factors are 1 and p if p is not prime it is composite The Fundamental Theorem of Arithmetic Every positive integer can be expressed as a unique product of primes

5 How many prime numbers are there? Is there a largest prime number? assume we know all the prime numbers let p be the largest prime multiply all the primes together add 1 call this n n is not divisible by 2, we get remainder 1 n is not divisible by 3, we get remainder 1 n is not divisible by 5, we get remainder 1 … n is not divisible by p, we get remainder 1 But, by the FTA we know n has a prime factorisation Therefore n must have a prime divisor > p Therefore there is no greatest prime Due to Euclid

6 Are there an infinite number of primes? Reformulate this as “For any n, is there a prime greater than n?” compute a new number x = n! + 1 i.e. x = 1.2.3.4.5.6…n-1.n + 1 x is not divisible by any number in the range 2 to n we always get remainder 1 the FTA states x is a product of primes x has a prime divisor x’s smallest prime divisor is greater than n Consequently for any n there is a prime greater than n Rosen, page 180, example 24

7 PRIMES Therefore, the divisor a or b is either prime or due to the fundamental theorem of arithmetic, can be expressed as a product of primes

8 How big a prime do we want? Page 148, for RSA encryption “The most efficient factorisation methods (1999) require billions of years to factor 400 digit integers. Consequently … when 200 digit primes … messages encrypted … cannot be found in a reasonable time.” “When new factorisation techniques are found … it will be necessary to use larger primes to ensure secrecy/security of messages.”

9 a divides b if a is not zero there is a c such that a.c = b “a is a factor of b” “b is a multiple of a” a|b Division

10 If a|b and a|c then a|(b+c) “ If a divides b and a divides c then a divides b plus c ” a|b  a.x = b a|c  a.y = c b+c = a.x + a.y = a(x + y) and that is divisible by a Division Note also: if a| b and a|c then a|(b-c)

11 a|b  a.x = b b.c = a.x.c which is divisible by a Division

12 a|b  a.x = b b|c  b.y = c c = a.x.y and that is divisible by a Division

13 The Division Algorithm (aint no algorithm) a is an integer and d is a positive integer there exists unique integers q and r, 0  r  d a = d.q. + r a divided by b = q remainder r dividend divisor quotient remainder NOTE: r is positive and d is positive

14 Greatest common divisor gcd(a,b) and Least common multiple gcd(a,b) is largest d such that d|a and d|b if gcd(a,b) = 1 then a and b are relative prime lcm(a,b) is the smallest/least x such that a|x and b|x 3 Naïve algorithms for gcd(a,b) start with x at 1 up to min(a,b) testing if x | a and x |b remember the last (largest) successful value start with x at min(a,b) and count down to 1 testing if x|a and x|b stop when the first value of x is found compute the prime factorisation of a and of b and then see below

15 Greatest common divisor gcd(a,b) gcd(120,500) prime factorisation of 120 is 2.2.2.3.5 prime factorisation of 500 is 2.2.5.5.5 20 … but there is a better algorithm

16 gcd, a geometric view We have a floor to tile The floor is 57 units wide and 152 units long What is the largest square tile we can use to tile the floor this will be the least number of square tiles! 57 152

17 57 19 gcd, a geometric view Find gcd(57,152) 19 is the answer we need 24 tiles

18 Theorem  when a = b.q + r  greatest common divisor of a and b is also  greatest common divisor of b and r  i.e. gcd(a,b) = gcd(b,r)

19 A proof follows The proof is based on what we already know about division

20 RTP: gcd(a,b) = gcd(b,r) where a = b.q + r Sketch of the proof Show that common divisors of a and b are also common divisors of b and r (1) show that if some d|a and d|b then d|r (2) show that if some d|b and d|r then d|a (3) conclude that a common divisor of a and b is also a common divisor of b and r (4) consequently gcd(a,b) = gcd(b,r)

21 RTP: gcd(a,b) = gcd(b,r) where a = b.q + r (1) show that if some d|a and d|b then d|r a = b.q + r  a - b.q = r We have already proved that if d|b then d|b.q if d|a and d|b.q then d|(a - b.q) since d|a and d|b.q it follows that d|(a - b.q) since (a - b.q) = r it follows that d|r Consequently a common divisor of a and b also divides r

22 RTP: gcd(a,b) = gcd(b,r) where a = b.q + r (2) show that if some d|b and d|r then d|a a = b.q + r We have already proved that if d|b then d|b.q if d|b.q and d|r then d|(b.q + r) since d|b.q and d|r it follows that d|(b.q + r) since (b.q + r) = a it follows that d|a Consequently a common divisor of b and r also divides a

23 RTP: gcd(a,b) = gcd(b,r) where a = b.q + r (3) conclude that a common divisor of a and b is also a common divisor of b and r From (1) and (2) we have proved that P a common divisor of a and b is also a divisor of r P a common divisor of b and r is also a divisor of a P consequently a common divisor of a and b is also a common divisor of b and r

24 RTP: gcd(a,b) = gcd(b,r) where a = b.q + r (4) consequently gcd(a,b) = gcd(b,r) From (3) we can conclude that the greatest common divisor of a and b is also a greatest common divisor of b and r

25 This suggests an algorithm  given a and b  if a = 0 then b is the gcd  if b = 0 then a is the gcd  otherwise  a  b = q remainder r  we have established that we can substitute  gcd(a,b) with gcd(b,r)  now compute gcd(b,r)  note, r is decreasing!

26 We have shown that when a = b.q + r any divisor of a and b is also a divisor of b and r consequently gcd(a,b) = gcd(b,r) We state that gcd(0,b) = b and gcd(a,0) = a therefore, there is nothing to do if a or b is zero Due to our theorem we can reduce gcd(a,b) to a simpler problem gcd(b,r) at each iteration we replace b with r where 0  r  b at each iteration b decreases eventually this must terminate with b = 0 and as we said, we are then done and a is the answer! gcd

27 gcd(a,b) if b = 0 then a else gcd(b,a mod b) gcd(a,b) while b  0 do begin r := a mod b; a := b; b := r; end; a (0) gcd(a,b) (1) if b = 0 goto 6 (2) let r := a mod b (3) a := b (4) b := r (5) goto (1) (6) return(a)

28

29 [gcd(a:integer,b:integer) : integer -> if (b = 0) a else gcd(b,a mod b)] [relativePrime(a:integer,b:integer) : boolean -> gcd(a,b) = 1] Try gcd(414,662) and then gcd(662,414) gcd(120,500) and gcd(500,120) list all numbers relative prime to 22

30 Numbers A number to the base b it has k+1 terms the a’s are all in the range 0 to b-1 what is 10101101 base 2 in base 10 peter base 26 in base 10

31 Numbers  Can you do arithmetic in different bases?  I expect so (see pages 169-177)  Can you do addition, multiplication, subtraction, division  in different bases? (I expect so)  Do you know the algorithm for this?  Again, I expect so.

32 Reading Please read the following Cryptology, pages 165-166 Representation of Integers, pages 169-177 … and the Footnote on page 177


Download ppt "AF2. Turn off your phones Primes, gcd, some examples, reading."

Similar presentations


Ads by Google