# Summary

We started today by looking for a generalization to Fermat's Little Theorem, and in doing so we conjectured what is known as Euler's Theorem. This theorem relates the number of residue classes that are relatively prime to *n* to a "magic exponent result" that has the flavor of Fermat's Little Theorem. After introducing the theory and giving a proof, we went on to compute values of Euler's $\phi$ function.

# Generalizing Fermat's Little Theorem

Last class period we finished by asking if we could find a generalization of *flt* that applies to composites. More specifically, for prime numbers *flt* says

For every integer

awith $(a,p) = 1$, the congruence $a^{p-1} \equiv 1 \mod{p}$.

We want to know whether there is a "magic exponent" e so that

For every integer

awith $(a,n) = 1$, the congruence $a^{e} \equiv 1 \mod{n}$.

After looking at the following chart

n | integers a between 1 and n relatively prime to n |
"magic exponent" |
---|---|---|

3 | $\{1,2\}$ | 2 |

5 | $\{1,2,3,4\}$ | 4 |

7 | $\{1,2,3,4,5,6\}$ | 6 |

we noticed that the "magic exponent" was the same number as the cardinality of residues that are relatively prime to *n*. This led us to the following definition and theorem:

Euler's $\phi$ function: For an integer

n, $\phi(n)$ is the number of integers between 1 andn(inclusive) which are relatively prime ton. This is also called Euler's Totient function.

Euler's Theorem: For any integer

nand anyasatisfying $(a,n) = 1$, one has $a^{\phi(n)} \equiv 1 \mod{n}$.

Before we start the proof, notice that this theorem is a generalization of Fermat's Little Theorem, meaning that it captures the statement of *flt* inside a more general theory. To see that this is true, note that for a prime number *p* we have $\phi(p) = p-1$, since all the integers $1, 2, \cdots, p-1$ have to be relatively prime to *p*. Hence if we apply Euler's Theorem for *p*, we get

which is just the statement of Fermat's Little Theorem.

Proof: To prove this theorem, let $S = \{r_1,r_2,\cdots,r_{\phi(n)}\}$ be the set of least non-negative residues which are relatively prime to *n*. For the given *a*, we'll denote by $T$ the set $T = \{ar_1,ar_2,\cdots,ar_{\phi(n)}\}$. We claim that *S* and *T* are the same modulo *n*. If this claim is true, notice that this means that the product of the elements in *S* is the same as the product of the elements in *T* — at least modulo *n*. Hence we'd have

Since each $r_i$ is relatively prime to *n*, one of our homework problems says that $\left(\prod_{i=1}^{\phi(n)} r_i,n\right) = 1$. Hence we can "cancel" the term $\prod_{i=1}^{\phi(n)} r_i$ from both sides of the expression, and we'll be left with the desired equation:

Hence all that's left is to verify the claim. To do this, we'll show that each of the elements of *T* is relatively prime to *n*, and that each of them is distinct from each other modulo *n*. For the first, notice that since both *a* and $r_i$ are relatively prime to *n*, their product is also relatively prime to *n*. Hence — modulo *n* — the elements of *T* are a subset of the elements of *S*. To show they're the same set, we'll show that *T* has $\phi(n)$ distinct elements, meaning that we need to show that $ar_i \equiv ar_j \mod{n}$ only when $i = j$. So suppose that $ar_i \equiv ar_j \mod{n}$. Since $(a,n) = 1$ we can "cancel" the *a*'s on both side of the equation, and so we have $r_i \equiv r_j \mod{n}$. Of course this can only happen when $i = j$, so we're done. $\square$

#### Example: Testing Euler's Theorem out

Let's try to verify that

(4)For this, we'll first need to compute $\phi(21)$, which we'll do by listing all the numbers between 1 and 21, and then crossing out the numbers which fail to be relatively prime to 21: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21. Note that there are 12 numbers remaining, and so $\phi(21) = 12$. Hence we need to verify that

(5)For this, we'll use our successive squaring trick:

(6)Hence we have

(7)$\square$

# Calculating the Phi function

Having done a computation, it's obvious that we need a more systematic way of computing the value of the phi function at a given number. For instance, if we wanted to compute $\phi(105)$, we wouldn't want to have to write out all numbers between 1 and 105 and cross out numbers which aren't relatively prime to 105. So let's see what we can say about the $\phi$ function.

We'll start with a class of numbers for which calculating the $\phi$ value is simple: the primes.

Lemma: If

pis a prime number, then $\phi(p) = p-1$.

Proof: We know that any integer $1 \leq a < p$ must be relatively prime to *p* because *p* is a prime number. Hence all $p-1$ of these numbers are relatively prime to *p*. Since *p* certainly isn't relatively prime to itself, this means that there are $p-1$ integers between 1 and *p* which are relatively prime to *p*. $\square$

Lemma: If

pis a prime number, then $\phi(p^a) = p^a-p^{a-1}$.

Proof: Notice that any number *n* for which $(n,p^a) > 1$ must be a multiple of *p*. Hence if we can list the multiples of *p* which fall between 1 and $p^a$, we'll have a complete list of elements in that range which aren't relatively prime to $p^a$; this will then let us compute home many numbers are relatively prime to $p^a$ by just subtracting these "bad elements" from the total number of integers between 1 and $p^a$.

So let's list the multiples of *p*:

We can see that there are $p^{a-1}$ such elements, and so the total number of integers between 1 and $p^a$ which aren't relatively prime to $p^a$ is $p^{a-1}$. This leaves $p^a-p^{a-1}$ elements which are relatively prime to $p^a$, and this gives us $\phi(p^a)$. $\square$

Lemma: If

pandqare distinct prime numbers, then $\phi(pq) = (p-1)(q-1) = \phi(p)\phi(q)$.

Proof: We'll proceed like last time, noting that numbers which aren't relatively prime to $pq$ are either multiples of *p* or multiples of *q*. This means that the numbers which aren't relatively prime sit in the lists:

The total number of terms in both lists is clearly $q+p$, but we need to account for overlap. For this, notice that elements which are in both lists are common multiples of *p* and *q*. We already know that the least common multiple of *p* and *q* is *pq*, and so the only element common to both lists is *qp*. Hence the total number of distinct elements between the two lists is $p+q-1$. This means that, in total, we have

elements which are relatively prime to *pq*. The fact that this number is the same as $\phi(p)\phi(q)$ follows from our formula for $\phi$ evaluated at primes. $\square$

# Refining Our Calculations

Now that we have some rules for calculating $\phi$, we can evaluate this function for lots of integers. For instance, we get

n | $\phi(n)$ |
---|---|

1 | 1 |

2 | 1 = 2-1 |

3 | 2 = 3-1 |

4 | 2 = 4^{2}-4^{1} |

5 | 4 = 5-1 |

6 | 2 = (2-1)(3-1) |

7 | 6 = 7-1 |

8 | 4 = 2^{3}-2^{2} |

9 | 6 = 3^{2}-3^{1} |

10 | 4 = (2-1)(5-1) |

11 | 10 = 11 - 1 |

Notice, that when we get to $12 = 2^2 \cdot 3$, however, we no longer have a clean formula for calculating $\phi(12)$. We can list the numbers between 1 and 12 easily enough and test for relative primality, however, and when we do so we see that $\phi(12) = 4$. Notice we have

(11)but that

(12)In class we'll talk about what's happening here and how we can use it to "crack the code" of the $\phi$ function.