56
Fermat's Little Theorem CS 2800: Discrete Structures, Spring 2015 Sid Chaudhuri

Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Fermat's Little Theorem

CS 2800: Discrete Structures, Spring 2015

Sid Chaudhuri

Page 2: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Not to be confused with...

Fermat's Last Theorem:xn + yn = zn has no integer solution for n > 2

Page 3: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Recap: Modular Arithmetic

● Definition: a ≡ b (mod m) if and only if m | a – b

● Consequences:

– a ≡ b (mod m) iff a mod m = b mod m

(Congruence ⇔ Same remainder)

– If a ≡ b (mod m) and c ≡ d (mod m), then● a + c ≡ b + d (mod m)● ac ≡ bd (mod m)

(Congruences can sometimes be treated like equations)

Page 4: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Fermat's Little Theorem

● If p is a prime number, and a is any integer, then

a p ≡ a (mod p)

Page 5: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Fermat's Little Theorem

● If p is a prime number, and a is any integer, then

a p ≡ a (mod p)

● If a is not divisible by p, then

a p – 1 ≡ 1 (mod p)

Page 6: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Fermat's Little Theorem

● Examples:– 217 ≡ 21 (mod 7)

… but 216 ≢ 1 (mod 7)

– 11112 ≡ 1 (mod 13)

– 123,456,789 257,885,161 − 2 ≡ 1 (mod 257,885,161 − 1)

Page 7: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Two proofs

● Combinatorial– … counting things

● Algebraic– … induction

● We'll consider only non-negative a– … the result for non-negative a can be extended to

negative integers(try it using what we know of congruences!)

Page 8: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Counting necklaces● Due to Solomon W. Golomb, 1956● Basic idea: a

p suggests we see how to fill p buckets, where each is filled with one of a objects

p buckets

a objects

Page 9: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Strings of beads

● Each way of filling the buckets gives a different sequence of p objects (“beads”)– a

p such sequences

S1 =

S2 =

S3 =

Page 10: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Strings of beads

● Now string the beads together...

Page 11: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Strings of beads

● … and join the ends to form “necklaces”

Page 12: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

A necklace rotated...

● … is the same necklace– Different strings can produce the same necklace when

the ends are joined

= =

Page 13: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Two types of necklaces

● Containing beads of a single color

Page 14: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Two types of necklaces

● Containing beads of a single color

● Only one possible string

Page 15: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Two types of necklaces

● Containing beads of different colors

● Many possible strings

Page 16: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Lemma

● If p is a prime number and N is a necklace with at least two colors, every rotation of N corresponds to a different string– … i.e. there are exactly p different strings that form the

same necklace N

Page 17: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● First, note that each string corresponds to– a rotation of the necklace, and then...– … cutting it at a fixed point

Page 18: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● No more than p strings can give the same necklace– There are only p (say clockwise) rotations of the

necklace (that align the beads) before we loop back to the original orientation

Page 19: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Now we'll show that no less than p strings give the same necklace

Page 20: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Now we'll show that no less than p strings give the same necklace

● Consider clockwise rotations by 1/p of a full circle

Page 21: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Now we'll show that no less than p strings give the same necklace

● Consider clockwise rotations by 1/p of a full circle● Let k be the minimum number of such rotations

before the original configuration is repeated

Page 22: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Now we'll show that no less than p strings give the same necklace

● Consider clockwise rotations by 1/p of a full circle● Let k be the minimum number of such rotations

before the original configuration is repeated– Clearly, k ≤ p (p rotations bring us back to the start)

Page 23: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Now we'll show that no less than p strings give the same necklace

● Consider clockwise rotations by 1/p of a full circle● Let k be the minimum number of such rotations

before the original configuration is repeated– Clearly, k ≤ p (p rotations bring us back to the start)

● Claim: k | p

Page 24: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

Page 25: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

Page 26: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

– q iterations, each of k rotations, restores the original configuration (by definition of k)

Page 27: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

– q iterations, each of k rotations, restores the original configuration (by definition of k)

– So do p rotations (full circle)

Page 28: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

– q iterations, each of k rotations, restores the original configuration (by definition of k)

– So do p rotations (full circle)– … therefore so do r rotations

Page 29: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

– q iterations, each of k rotations, restores the original configuration (by definition of k)

– So do p rotations (full circle)– … therefore so do r rotations– But r < k and we said k was the minimum “period”!

Page 30: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Claim● Claim: k | p

● Proof:– Let p = qk + r, with 0 ≤ r < k (division algorithm)

– q iterations, each of k rotations, restores the original configuration (by definition of k)

– So do p rotations (full circle)– … therefore so do r rotations– But r < k and we said k was the minimum “period”!– … which is a contradiction, unless r = 0

Page 31: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Since k | p and k ≤ p and p is prime, we must have either

Page 32: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Since k | p and k ≤ p and p is prime, we must have either– k = 1 (impossible if necklace has at least two colors)

Page 33: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Since k | p and k ≤ p and p is prime, we must have either– k = 1 (impossible if necklace has at least two colors)

or– k = p

Page 34: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Proof of Lemma

● Since k | p and k ≤ p and p is prime, we must have either– k = 1 (impossible if necklace has at least two colors)

or– k = p

● This proves the lemma

Page 35: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far

Page 36: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

Page 37: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

Page 38: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

● Necklaces with multiple colors

Page 39: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

● Necklaces with multiple colors– Each corresponds to p different strings

Page 40: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

● Necklaces with multiple colors– Each corresponds to p different strings

– a p – a strings of multiple colors, therefore (a p – a) / p such necklaces

Page 41: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

● Necklaces with multiple colors– Each corresponds to p different strings

– a p – a strings of multiple colors, therefore (a p – a) / p such necklaces

⇒ p | a p – a (can't have half a necklace)

Page 42: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

What we have so far● Necklaces with one color

– a such strings (one for each color), therefore a such necklaces

● Necklaces with multiple colors– Each corresponds to p different strings

– a p – a strings of multiple colors, therefore (a p – a) / p such necklaces

⇒ p | a p – a

⇒ a p ≡ a (mod p) QED!

(can't have half a necklace)

Page 43: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

Page 44: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a

Page 45: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

Page 46: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

● Inductive hypothesis: a p ≡ a (mod p)

Page 47: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

● Inductive hypothesis: a p ≡ a (mod p)

● Consider (a + 1) p

Page 48: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

● Inductive hypothesis: a p ≡ a (mod p)

● Consider (a + 1) p

● By the Binomial Theorem,

(a+1)p=a p+( p1 )a p−1+(p2 )ap−2+( p3 )a p−3+...+( pp−1)a+1

Page 49: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

● Inductive hypothesis: a p ≡ a (mod p)

● Consider (a + 1) p

● By the Binomial Theorem,

– All RHS terms except last & perhaps first are divisible by p

(a+1)p=a p+( p1 )a p−1+(p2 )ap−2+( p3 )a p−3+...+( pp−1)a+1

Page 50: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● For a given prime p, we'll do induction on a● Base case: Clear that 0 p ≡ 0 (mod p)

● Inductive hypothesis: a p ≡ a (mod p)

● Consider (a + 1) p

● By the Binomial Theorem,

– All RHS terms except last & perhaps first are divisible by p

(a+1)p=a p+( p1 )a p−1+(p2 )ap−2+( p3 )a p−3+...+( pp−1)a+1

Binomial coefficient ( ) is

p!/ k!(p – k)!, which is always an integer. p is prime, so it isn't canceled out by terms in the denominator

pk

Page 51: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

Page 52: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

● But by the inductive hypothesis, a p ≡ a (mod p)

Page 53: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

● But by the inductive hypothesis, a p ≡ a (mod p)

⇒ a p + 1 ≡ a + 1 (mod p) (properties of congruence)

Page 54: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

● But by the inductive hypothesis, a p ≡ a (mod p)

⇒ a p + 1 ≡ a + 1 (mod p) (properties of congruence)

● Therefore (a + 1) p ≡ a + 1 (mod p)

Page 55: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

● But by the inductive hypothesis, a p ≡ a (mod p)

⇒ a p + 1 ≡ a + 1 (mod p) (properties of congruence)

● Therefore (a + 1) p ≡ a + 1 (mod p)

(congruence is transitive – prove!)

Page 56: Fermat's Little Theorem - Cornell University€¦ · Fermat's Little Theorem ... Necklaces with one color – a such strings (one for each color), therefore a such necklaces Necklaces

Another proof (algebraic)

● Therefore (a + 1) p ≡ a p + 1 (mod p)

● But by the inductive hypothesis, a p ≡ a (mod p)

⇒ a p + 1 ≡ a + 1 (mod p) (properties of congruence)

● Therefore (a + 1) p ≡ a + 1 (mod p)

(congruence is transitive – prove!)

● Hence proved by induction