TITLE: Second moment for the number of divisors function
QUESTION [5 upvotes]: Let $d(n)$ be the number of divisors of an integer $n$.
Does there exists a bound for $\sum_{k\leq n}d^2(k)$?
I saw in a paper of Barry and Louboutin that the asymptotics is $\frac1{\pi^2}nlog^3n$ but there was no proof nor a reference or any indication that this is the best possible bound.
Any idea where can I find this?
Thanks.

REPLY [9 votes]: Inspired by Gerry Myerson's comment, I present below an elementary argument that does not use any complex analysis. 
Our starting point is the identity
$$ d^2(k)=\sum_{k=l^2m}\mu(l)d_4(m), $$
where $d_4(m)$ enumerates the number of decompositions $m=m_1m_2m_3m_4$. By the multiplicative nature of this equation, it suffices to verify it when $m=p^r$ is a prime power. In this case the identity boils down to
$$ (r+1)^2=\binom{r+3}{3}-\binom{r+1}{3}, $$
which is straightforward to check. With the above identity at hand, we rewrite
$$ \sum_{k\leq n}d^2(k)=\sum_{l^2m\leq n}\mu(l)d_4(m)=\sum_{l\leq\sqrt{n}}\mu(l)\sum_{m\leq\frac{n}{l^2}}d_4(m). $$
We approximate the inner sum by Dirichlet's hyperbola method (cf. Exercise 2 in Section 1.5 of Iwaniec-Kowalski: Analytic Number Theory), and we obtain
$$ \sum_{k\leq n}d^2(k)=\sum_{l\leq\sqrt{n}}\mu(l)\frac{n}{6l^2}\left\{\log^3\left(\frac{n}{l^2}\right)+O\left(\log^2\left(\frac{n}{l^2}\right)\right)\right\}. $$
It follows that
$$ \sum_{k\leq n}d^2(k)=\frac{n\log^3(n)}{6}\left(\sum_{l\leq\sqrt{n}}\frac{\mu(l)}{l^2}\right)+O\left(n\log^2(n)\right) =\frac{n\log^3(n)}{6\zeta(2)}+O\left(n\log^2(n)\right).$$
Finally, using $\zeta(2)=\pi^2/6$ as a black box, we obtain the formula asked by the OP.