I was wondering how I could show that $\displaystyle \sum_{x\leq Z}d(x)^2\ll Z(\log 2Z)^3$, where $d(x)$ counts the number of divisors of $x$. I tried to prove this in the following fashion (and failed spectacularly):
Wlog assume $Z$ is an integer. Note that we have for a given $\epsilon>0$, there exists a constant $C$ depending on $\epsilon$ such that $|d(m)|\leq Cm^{\epsilon}$, i.e. $d(m)\ll m^{\epsilon}$. Summing, we have $\displaystyle \sum_{x\leq Z}d(x)^2\leq 1+\dots+Z^{2\epsilon}\dots \boxed{1}$. Next, we consider the function $f(x)=x^{2\epsilon}$ and note that the sum in $\boxed{1}$ is less than or equal to $\displaystyle \int_1^Zf(x)\mathrm{d}x=-\frac{1}{2\epsilon+1}+\frac{(Z+1)^{2\epsilon+1}}{2\epsilon+1}\leq \frac{(Z+1)^{2\epsilon+1}}{2\epsilon+1}\ll Z (Z+1)^{2\epsilon}$. This however doesn't seem to tell me how to proceed from here. Of course, taking $\epsilon$ to be $3/2$, we obtain $\displaystyle \sum_{x\leq Z}d(x)^2\ll Z(Z+1)^3$ Thank you for any insights.
To show just the domination $$\sum_{n \leqslant Z} d(n)^2 \ll Z(\log Z)^3$$ (for $Z \geqslant 2$, so that I can use $\log Z$ instead of $\log (2Z)$) we can use a simple but non-obvious trick. For notational convenience and transparency I'll use the Iverson bracket $$[P] = \begin{cases} 1 &\text{if } P, \\ 0 &\text{if } \lnot P. \end{cases}$$ The trick consists of writing $$d(n) = \sum_{k \mid n} 1 = \sum_{k \leqslant Z} [k \mid n]$$ for $n \leqslant Z$ and then changing the order of summation:
\begin{align} \sum_{n \leqslant Z} d(n)^2 &= \sum_{n \leqslant Z} d(n)\cdot \sum_{k \leqslant Z} [k \mid n] \\ &= \sum_{k \leqslant Z} \sum_{n \leqslant Z} [k \mid n]\cdot d(n) \\ &= \sum_{k \leqslant Z} \sum_{m \leqslant Z/k} d(k\cdot m). \end{align} Next we use the complete submultiplicativity of the divisor counting function, $d(k\cdot m) \leqslant d(k)\cdot d(m)$ for all positive integers $k,m$. This is immediate from $1 + a + b \leqslant (1+a)(1+b) = 1 + a + b + ab$ for $a, b \geqslant 0$. Thus we obtain \begin{align} \sum_{n \leqslant Z} d(n)^2 &= \sum_{k \leqslant Z} \sum_{m \leqslant Z/k} d(km) \\ &\leqslant \sum_{k \leqslant Z} d(k)\sum_{m \leqslant Z/k} d(m) \\ &\ll \sum_{k \leqslant Z} d(k)\cdot \frac{Z}{k}\log \frac{Z}{k} \\ &\leqslant Z\log Z \sum_{k \leqslant Z} \frac{d(k)}{k} \\ &\sim Z\log Z\cdot \frac{1}{2}(\log Z)^2 \\ &\ll Z(\log Z)^3. \end{align}