<s>[INST] Average order of Eulers totient function squared I was wondering if one has a nice asymptotic formula for the sum
$$\sum_{n\le x} \phi(n)^2$$
and if so, how does one calculate it. I know that one has $\sum_{n\le x} \phi(n) = \frac{3}{\pi^2}x^2+O(x\log x)$, but I can't seem to find similar results for other powers of $\phi$.
 [/INST] We can get  the first term of the  asymptotics with the Wiener-Ikehara
theorem. For this purpose we need to evaluate
$$L(s) = \sum_{n\ge 1} \frac{\varphi(n)^2}{n^s}.$$
Recall that 
$$ n = \prod_p p^v \quad\text{implies}\quad
\varphi(n) = \prod_{p|n} (p^v - p^{v-1})$$
which we may  either quote or derive using  the fact that $\varphi(n)$
is multiplicative  and the  fact that there  are $p^{v-1}$  values not
coprime to $p^v$ in the interval $[1, p^v].$

This implies that $L(s)$ has the following Euler product:
$$\prod_p 
\left(1 + \frac{(p-1)^2}{p^s} + \frac{(p^2-p)^2}{p^{2s}} + 
\frac{(p^3-p^2)^2}{p^{3s}} + \frac{(p^4-p^3)^2}{p^{4s}} +
\cdots\right).$$
Expanding the squares we get
$$\prod_p
\left(1 + \sum_{q\ge 1} \frac{p^{2q}}{p^{qs}}
- 2 \sum_{q\ge 1} \frac{p^{2q-1}}{p^{qs}}
+ \sum_{q\ge 1} \frac{p^{2q-2}}{p^{qs}}\right).$$
This is
$$\prod_p
\left(1 +
\left(1 - \frac{2}{p} + \frac{1}{p^2} \right)
\sum_{q\ge 1} \frac{p^{2q}}{p^{qs}}
\right)
= \prod_p \left(1 +
\left(1 - \frac{2}{p} + \frac{1}{p^2} \right)
\frac{p^{2-s}}{1-p^{2-s}}
\right)
\\ = \prod_p \left(1 +
\left(1 - \frac{2}{p} + \frac{1}{p^2} \right)
\frac{p^{2-s}}{1-1/p^{s-2}}
\right)
\\ =  \zeta(s-2)
\prod_p \left(1 - 1/p^{s-2} +
p^{2-s} - 2 p^{1-s} + p^{-s} \right)
\\ =  \zeta(s-2)
\prod_p \left(1 - 2 \frac{1}{p^{s-1}} + 
\frac{1}{p^s} \right).$$
There  is a  simple pole  at  $s=3$ (from the zeta function which contributes one to the residue and the  product, which is  readily seen  to converge there) and hence by the
Wiener-Ikehara Theorem
we have
$$\sum_{n\le x} \varphi(n)^2
\sim \frac{x^3}{3}
\prod_p \left(1 - 2 \frac{1}{p^{2}} + 
\frac{1}{p^3} \right).$$
Convergence of the product follows because we have
$$0 < \frac{2}{p^2} - \frac{1}{p^3} < 1 $$
and $$\sum_p \left( \frac{2}{p^{2}} 
- \frac{1}{p^3} \right)$$
converges e.g. by comparison with $\zeta(2)$ and $\zeta(3).$

The numeric value of the constant is given by
$$\prod_p \left(1 - 2 \frac{1}{p^{2}} + 
\frac{1}{p^3} \right)
\approx 0.428249.$$

This material is not original and can be found at
OEIS 127473.
</s>