[proofplan]
The proof separates the case $n=1$, where all products are empty, from the case in which the prime factorisation has at least one prime factor. For $r\geq 1$, we define the prime-power factors $q_i=p_i^{a_i}$ and observe that they are pairwise coprime because the primes $p_i$ are distinct. We then apply multiplicativity of $\varphi$ repeatedly to reduce $\varphi(n)$ to the product of the prime-power values, and finally insert the formula for $\varphi(p^a)$ and factor the resulting product.
[/proofplan]
custom_env
admin
[step:Handle the empty prime factorisation case]
If $r=0$, then the displayed factorisation gives $n=1$ by the empty product convention. By the standard definition of Euler's totient function, $\varphi(1)=1$, since the unique residue class modulo $1$ is the multiplicative identity in the one-element ring. The product
\begin{align*}
\prod_{i=1}^0 p_i^{a_i-1}(p_i-1)
\end{align*}
is empty and hence equals $1$. Likewise,
\begin{align*}
1\prod_{i=1}^0\left(1-\frac{1}{p_i}\right)=1.
\end{align*}
Thus both asserted formulas hold when $r=0$.
[/step]
custom_env
admin
[step:Show that the prime-power factors are pairwise coprime]Assume now that $r\geq 1$. For each $i\in\{1,\dots,r\}$, define the integer
\begin{align*}
q_i:=p_i^{a_i}.
\end{align*}
Then
\begin{align*}
n=\prod_{i=1}^r q_i.
\end{align*}
We claim that the integers $q_1,\dots,q_r$ are pairwise coprime. Let $i,j\in\{1,\dots,r\}$ with $i\neq j$. Since $p_i$ and $p_j$ are distinct primes, no prime divides both $p_i$ and $p_j$. Hence no prime divides both powers $p_i^{a_i}$ and $p_j^{a_j}$. Therefore the only positive common divisor of $q_i$ and $q_j$ is $1$, so
\begin{align*}
\gcd(q_i,q_j)=1.
\end{align*}[/step]
custom_env
admin
[guided]We now isolate the part of the factorisation to which multiplicativity can be applied. For each index $i\in\{1,\dots,r\}$, set
\begin{align*}
q_i:=p_i^{a_i}.
\end{align*}
Thus $q_i$ is the $i$th prime-power factor of $n$, and the given factorisation becomes
\begin{align*}
n=\prod_{i=1}^r q_i.
\end{align*}
The multiplicativity theorem for $\varphi$ applies to products of coprime integers, so we must verify coprimality before using it. Take two different indices $i,j\in\{1,\dots,r\}$. The primes $p_i$ and $p_j$ are distinct by hypothesis. A common positive divisor of $p_i^{a_i}$ and $p_j^{a_j}$ cannot have any prime divisor: every prime divisor of $p_i^{a_i}$ is $p_i$, while every prime divisor of $p_j^{a_j}$ is $p_j$. Since $p_i\neq p_j$, there is no prime that can divide both powers. Hence the common positive divisor has no prime divisor, and therefore it must be $1$. This proves
\begin{align*}
\gcd(q_i,q_j)=1.
\end{align*}
Since the indices $i$ and $j$ were arbitrary and distinct, the family $q_1,\dots,q_r$ is pairwise coprime.[/guided]
custom_env
admin
[step:Apply multiplicativity to the product of coprime prime powers]
We prove by induction on $r\geq 1$ that
\begin{align*}
\varphi\left(\prod_{i=1}^r q_i\right)=\prod_{i=1}^r \varphi(q_i).
\end{align*}
For $r=1$, this is the identity $\varphi(q_1)=\varphi(q_1)$. Suppose the formula holds for some $r-1\geq 1$. Define
\begin{align*}
Q:=\prod_{i=1}^{r-1} q_i.
\end{align*}
Because each $q_i$ with $i<r$ is coprime to $q_r$, their product $Q$ is coprime to $q_r$, so
\begin{align*}
\gcd(Q,q_r)=1.
\end{align*}
By the [multiplicativity of Euler's totient function](/theorems/7886) [citetheorem:7886],
\begin{align*}
\varphi(Qq_r)=\varphi(Q)\varphi(q_r).
\end{align*}
Using the induction hypothesis on $Q$ gives
\begin{align*}
\varphi\left(\prod_{i=1}^r q_i\right)=\left(\prod_{i=1}^{r-1}\varphi(q_i)\right)\varphi(q_r).
\end{align*}
Therefore
\begin{align*}
\varphi\left(\prod_{i=1}^r q_i\right)=\prod_{i=1}^r \varphi(q_i).
\end{align*}
Since $n=\prod_{i=1}^r q_i$, we obtain
\begin{align*}
\varphi(n)=\prod_{i=1}^r \varphi(q_i).
\end{align*}
[/step]
custom_env
admin
[step:Insert the prime-power totient formula]
For each $i\in\{1,\dots,r\}$, the integer $p_i$ is prime and $a_i\in\mathbb{N}$, so the prime-power formula for Euler's totient function [citetheorem:7885] gives
\begin{align*}
\varphi(q_i)=\varphi(p_i^{a_i})=p_i^{a_i}-p_i^{a_i-1}.
\end{align*}
Factoring the right-hand side gives
\begin{align*}
p_i^{a_i}-p_i^{a_i-1}=p_i^{a_i-1}(p_i-1).
\end{align*}
Substituting this into the product obtained above yields
\begin{align*}
\varphi(n)=\prod_{i=1}^r p_i^{a_i-1}(p_i-1).
\end{align*}
[/step]
custom_env
admin
[step:Factor out $n$ to obtain the equivalent Euler product]
For each $i\in\{1,\dots,r\}$, since $p_i$ is prime, $p_i\neq 0$ in $\mathbb{Z}$, and hence
\begin{align*}
p_i^{a_i-1}(p_i-1)=p_i^{a_i}\left(1-\frac{1}{p_i}\right).
\end{align*}
Therefore
\begin{align*}
\prod_{i=1}^r p_i^{a_i-1}(p_i-1)=\prod_{i=1}^r p_i^{a_i}\left(1-\frac{1}{p_i}\right).
\end{align*}
Using the elementary rule for products, this becomes
\begin{align*}
\prod_{i=1}^r p_i^{a_i}\left(1-\frac{1}{p_i}\right)=\left(\prod_{i=1}^r p_i^{a_i}\right)\left(\prod_{i=1}^r\left(1-\frac{1}{p_i}\right)\right).
\end{align*}
Since $n=\prod_{i=1}^r p_i^{a_i}$, we conclude that
\begin{align*}
\varphi(n)=n\prod_{i=1}^r\left(1-\frac{1}{p_i}\right).
\end{align*}
This completes the proof of both formulas.
[/step]