what is the sum of square of all elements in $U(n)$? I know that $\sum\limits_{a\in U(n)} a=\frac{n\varphi(n)}{2}$ where $U(n):=\{1\leq r\leq n: (r, n)=1\}$ is a multiplicative group. And I know how to prove this result.
What I was willing to know was this $\sum\limits_{a\in U(n)} a^2$. is it possible to find in closed form?
what I tried is the following:
Let $S=\sum\limits_{a\in U(n)} a^2$. Now $(n, a)=1$ shows that $(n, n-a)=1$ which again under the fact  $(a, b)=1, (a, c)=1\Rightarrow (a, bc)=1$, shows that $(n, (n-a)^2)=1$. Hence $\{(n-a_1)^2, \cdots, (n-a_{\varphi(n)})^2\}$ is nothing but a permutation of the original set $\{a_1^2, \cdots, a_{\varphi(n)}^2\}$ in some order. Hence $S=\sum\limits_{a\in U(n)} (n-a)^2$. 
In other words we must have:
\begin{align*}
S=&\sum\limits_{a\in U(n)} (n^2-2an+a^2)\\
 =&n^2 \sum\limits_{a\in U(n)} 1-2n\sum\limits_{a\in U(n)} a+S\\
 =&n^2\varphi(n) -2n\times \frac{n\varphi(n)}{2}+S\\
 =&S
\end{align*}
and no result is obtained. 
What to do ? Please help me. 
Thanks
EDIT:
After the link has been provided below by Robert Israel
the formula reads $ n = p_1^{a_1}p_2^{a_2}\cdots p_r^{a_r}$ then $S = n^2\frac{\varphi(n)}{3}+(-1)^r p_1p_2\cdots p_r\frac{\varphi(n)}{6}$ but how to establish this ?

See OEIS sequence A053818 and references there.
