Prove $n$ is square-free when $ \left(\sum_{k=1}^{n}[k,n]^{(k,n)}, n^3\right)=n^2 $ How to prove the following statement:
If $n\in\mathbb{N}$ satisfies:
$$
\left(\sum_{k=1}^{n}[k,n]^{(k,n)}, n^3\right)=n^2
$$
where $[k,n]$ and $(k,n)$ are the least common multiple resp. the greatest common divisor of $k$ and $n$, then $n$ is square-free.
I started with tackling the sum:
$$
\sum_{k=1}^{n}[k,n]^{(k,n)}=\sum_{d|n}\sum_{1≤k≤n,\space (k,n)=d}{\left(\frac{kn}{d}\right)^d}=\sum_{d|n}n^d\sum_{1≤k≤\frac{n}{d},\space \left(k,\frac{n}{d}\right)=1}{k^d}=\sum_{d|n}n^d\varphi_{d}\left(\frac{n}{d}\right)
$$
Where I defined $\varphi_{r}(a):=\sum_{1≤k≤a, \space (k,a)=1}{k^r}$
I think this could help, because we can see the powers of n. However, I could not apply it correctly.
Note:
There exist solutions greater than $1$, for example $n=15$ or $n$ prime.
Progress:
For $n$ odd, we have 
$$\sum_{k=1}^{n}[k,n]^{(k,n)}=\sum_{d|n}n^d\varphi_{d}\left(\frac{n}{d}\right)\equiv n\varphi_1(n) \space \mod{n^3}$$
and for $n$ even:
$$
\sum_{k=1}^{n}[k,n]^{(k,n)}=\sum_{d|n}n^d\varphi_{d}\left(\frac{n}{d}\right)\equiv n\varphi_1(n)+n^2\varphi_2\left(\frac{n}{2}\right) \space \mod{n^3}
$$
Furthermore:
$$
\varphi_1(n)=\sum_{1≤k≤n, \space (k,n)=1}k=\sum_{1≤k≤n, \space (k,n)=1}n-k\implies\\
2\varphi_1(n)=\sum_{1≤k≤n, \space (k,n)=1}n=n\varphi(n)\implies \varphi_1(n)=\frac{n\varphi(n)}{2}
$$
So we can see for $n$ odd:
$$
\sum_{k=1}^{n}[k,n]^{(k,n)}\equiv \frac{n^2\varphi(n)}{2}\space\mod{n^3}
$$
and $n$ even:
$$
\sum_{k=1}^{n}[k,n]^{(k,n)}\equiv \frac{n^2\varphi(n)}{2}+n^2\varphi_2\left(\frac{n}{2}\right)\space\mod{n^3}
$$
How to finish it?
 A: For $n$ odd, you point out that
$$\sum_{k=1}^{n}[k,n]^{(k,n)}\equiv \frac{n^2\varphi(n)}{2}\space\mod{n^3},$$
so that
$$\left(\sum_{k=1}^{n}[k,n]^{(k,n)}, n^3\right)
       = \left( \frac{n^2\varphi(n)}{2}, n^3\right).$$
But this $\gcd$ is equal to $n^2$ precisely when $(n,\varphi(n)) = 1$, which can be the case only if $n$ is squarefree. This takes care of the case where $n$ is odd.
Finally we show that no even $n$ satisfy the condition. Suppose $n=2r$; then
$$
  \left(\sum_{k=1}^{n}[k,n]^{(k,n)},n^3\right)
    = \left(\frac{n^2\varphi(n)}{2}+n^2\varphi_2\left(\frac{n}{2}\right),n^3\right) 
    = (2r^2\varphi(2r) + 4r^2\varphi_2(r),8r^3).
$$
If $r$ is even, this is equal to
$$(4r^2\varphi(r) + 4r^2\varphi_2(r),8r^3) = 4r^2(\varphi(r) + \varphi_2(r),2r).$$
Clearly $\varphi(r)$ is even (note that $r=2$, $n=4$ does not satisfy the condition), so that $\varphi_1(r) = \frac{r\varphi(r)}{2}$ is also even; it follows that $\varphi_1(r)$ has an even number of odd summands, so that $\varphi_2(r)$ is also even. Thus $(\varphi(r) + \varphi_2(r),r)\ge 2$ and therefore $(4r^2\varphi(r) + 4r^2\varphi_2(r),8r^3) \ge 8r^2 = 2n^2$.
On the other hand (and finally), if $r$ is odd, then we get
$$(2r^2\varphi(r) + 4r^2\varphi_2(r),8r^3) = 2r^2(\varphi(r) + 2\varphi_2(r),4r).$$
As above, $\varphi(r)$ is even, so that $\varphi_2(r)$ is also even. Additionally, if $r$ contains at least two odd primes as factors, then $\varphi(r)\equiv 0\mod{4}$ and then the gcd is at least $2r^2\cdot 4 = 8r^2 = 2n^2$. So we are reduced to the case where $r = p^k$ for $p$ an odd prime. Note that
\begin{equation*}
  \varphi_2(n) = \frac{1}{3}n^2\varphi(n) + \frac{n}{6}\prod_{p\mid n}(1-p).
\end{equation*}
(This is Exercise 15, p. 48 of Apostol's book on Analytic Number Theory.)
We get
\begin{align*}
  \varphi(p^k) + 2\varphi_2(p^k) 
    &= p^{k-1}(p-1)+\frac{2}{3}p^{2k}p^{k-1}(p-1)-\frac{p^k}{3}(p-1) \\
    &= \frac{1}{3}p^k(p-1)(2p^{2k}-p+3),
\end{align*}
which is clearly $\equiv 0\mod{4}$.
So in this case as well, $2r^2(\varphi(r) + 2\varphi_2(r),4r) \ge 8r^2 = 2n^2$.
Thus no even $n$ satisfy the condition, and the result is proved.
