Day 25 4/15/98 ``You have to squint a little.''

1.  Primality Testing

Is n prime or composite? We want an algorithm that runs in (logn)k .

1.1  Fermat's little theorem

If p is prime with 1 < a < p then ap-1 = 1modp

1.2  contrapositive

If 1 < a < n and an-1 ¹ 1modn then n is composite.

1.3  Primality test heuristic

  1. guess a
  2. check if an-1 ¹ 1modn If yes output 'composite' otherwise output 'possibly prime'

This heuristic fails for certain numbers known as Carmicheal numbers. Example:

561 = 3*11*17

If GCD(a,n) = 1 then an-1 = 1modn

n is Carmicheal if

  1. n is composite
  2. l(n) divides n-1 with n = p1a1...pmam and l(n) = LCM(p1a1-1(p1-1),...,pmam-1(pm-1))

Carmicheal numbers actually always have ai = 1 and m ³ 3 .

1.4  More number theory (from gauss)

±1 are the only roots of x2 = 1modp with p prime

1.5  Better algorithm

A( a,n )

let n-1 = 2tu for u odd

  1. if n = 2 output 'prime'
  2. if n is even, output 'composite'
  3. if au = 1modn output 'possibly prime'
  4. if a2ju = -1modn for 1 £ j < t output 'possibly prime'
  5. else, output 'composite'

1.6  Theorem

half the a Î [1,n] for n composite will have that A(a,n) return 'composite'.

This means that if you run A(a,n) 100 times each time putting out 'possibly prime' then either n is prime or you are very unlucky.

1.7  Some number theory

1.7.1 Chinese remainder theorem

For n = p1a1*...*pmam

we have: Zn @ Zp1a1×Zpmam

For a Î Zn a® (amodp1a1,...,amodpmam)

1.7.2 multiplicative group

Zn* = {a Î Zn|$a¢with a¢*a = 1modn} = {a Î Zn|GCD(a,n) = 1}

If p is an odd prime, then Zp* is a cyclic group, which means every invertible element can be found by multiplying some base (a 'generator') modp .

1.8  Pulling all the facts together

if n = 5*7 then Z35* @ Z5*×Z7* @ C4*C6 then there will be many solutions to x2 = 1mod35 .

For 35, x = 1,6,-6,34 will work.

Working in the decomposed group, we get:

  1. 1® (1,1)
  2. 6® (1,-1)
  3. -6® (-1,1)
  4. 34® (-1,-1)

62 = 1mod35 = a 'nontrivial square root of 1' => 35 is composite.


File translated from TEX by TTH, version 1.30.