TITLE: Proof of the formula for Euler's totient function
QUESTION [9 upvotes]: I read on a forum somewhere that the totient function can be calculated by finding the product of one less than each of the number's prime factors. For example, to find $\phi(30)$, you would calculate $(2-1)\times (3-1)\times (5-1) = 8$.
I can't seem to get my head round why this works and don't know what to type in to google to find a formal proof. Could someone please explain in an easy to understand way why this works.

REPLY [2 votes]: Here is an alternative explanation that some might find easy to understand.  The fraction $\phi(n)/n$ represents the probability that a random number $k$ chosen from $\{1,\ldots,n\}$ is relatively prime to $n$.  This event occurs precisely when $k$ is not divisible by any of the prime factors of $n$.
For each prime $p$ dividing $n$, let $E_p$ be the event that $k$ is divisible by $p$.  Note that $\mathbb P(E_p) = \tfrac1p$ (can you see why this is only accurate when $p$ divides $n$?).
The key step is using the Chinese Remainder Theorem to see that if $p_1, p_2, \ldots, p_r$ are any distinct primes dividing $n$, then the events $E_{p_1}, E_{p_2}, \ldots, E_{p_r}$ are independent: being even does not affect your chances of being divisible by $3$ (again, note that this is only precisely true because $n$ is a multiple of the LCM of those primes).
In particular we might as well choose $p_1, p_2, \ldots, p_r$ to be all the primes dividing $n$.  In this case, since $\phi(n)/n$ is the probability that none of these events occur, we have
$$\frac{\phi(n)}{n} = \mathbb P(\overline{E_{p_1}} \cap \overline{E_{p_2}} \cap \cdots\cap\overline{E_{p_r}}) =  \mathbb P(\overline{E_{p_1}})\mathbb P(\overline{E_{p_2}})\cdots \mathbb P(\overline{E_{p_r}}) = (1-\tfrac1{p_1})(1-\tfrac1{p_2})\cdots(1-\tfrac1{p_r}).$$