The asymptotic expansion for the weighted sum of divisors $\sum_{n\leq x} \frac{d(n)}{n}$ I am trying to solve a problem about the divisor function. Let us call $d(n)$ the classical divisor function, i.e. $d(n)=\sum_{d|n}$ is the number of divisors of the integer $n$. It is well known that the sum of $d(n)$ over all positive integers from $n=1$ to $x$, when $x$ tends to infinity, is asymptotic to $$x \ln(x) + (2 \gamma-1) x + O(\sqrt{x})$$
I would like to calculate a similar asymptotic expression for the sum of $d(n)/n$, again calculated from $n=1$ to $x$ and for $x$ that tends to infinity. I have made some calculations and obtained the  formula 
$$1/2 (\ln(x))^2 + 2 \gamma \ln (x) + O(1)$$ 
where gamma is the Euler-Mascheroni constant. I am interested in the constant term of the expression, which seems to be around $0.48$. I suspect that it could correspond to $\gamma^2 - 2\gamma_1$,   where $\gamma_1$ is the first Stieltjes constant ($-0.072...$). Could someone confirm this to me? 
As an additional question, I would be very interested in obtaining similar asymptotic formulas, with explicitly given constant terms,  for the same sum of $d(n)/n$ calculated over all odd integers from $1$ to $x$, and for that calculated over all even integers from $1$ to $x$. 
Many thanks. 
 A: I can confirm Eric Naslund's excellent work using a different method, namely the following version of the Mellin-Perron summation formula:
$$\sum_{k=1}^{n-1} \sum_{m=1}^k \lambda_m =
\frac{n}{2\pi i} \int_{c-i\infty}^{c+i\infty} \Lambda(s) n^s \frac{ds}{s(s+1)}$$
where $$\Lambda(s) = \sum_{k\ge 1}\frac{\lambda_k}{k^s}.$$
This will produce an asymptotic expansion of $q(n-1)$ where
$$q(n-1) = \sum_{k=1}^{n-1} \sum_{m=1}^k \frac{d(m)}{m}$$
so that $q(n)-q(n-1)$ is the asymptotic expansion we are looking for. The reason we do it this way is because the quotient by $s(s+1)$ ensures absolute convergence of certain integrals that appear later on, where a quotient of $s$ alone would not suffice. 
The Dirichlet series in question is
$$ \Lambda(s) = \sum_{n\ge 1} \frac{d(n)/n}{n^s} = \zeta(s+1)^2$$
so that
$$ q(n-1) = 
\frac{n}{2\pi i} \int_{1/2-i\infty}^{1/2+i\infty} \zeta(s+1)^2 n^s \frac{ds}{s(s+1)}.$$
Now we have
$$\operatorname{Res}\left(\zeta(s+1)^2 \frac{n^s}{s(s+1)}; s=0\right)
= \frac{1}{2} \log^2 n + (2\gamma-1)\log n + (\gamma-1)^2 - 2\gamma_1.$$
We pick up this residue when we shift the integral to the line $\Re(s) = -1/2.$
This almost concludes the computation, we only need to estimate the remainder term which is done as follows. First write
$$ \frac{1}{2\pi i} 
\int_{-1/2-i\infty}^{-1/2+i\infty} \zeta(s+1)^2 n^s \frac{ds}{s(s+1)} =
\frac{1}{\sqrt{n}}\frac{1}{2\pi} \int_{-\infty}^{\infty}
\zeta(1/2+it)^2 \frac{e^{it\log n}}{(-1/2+it)(1/2+it)} dt.$$
Now $1/2+it$ is on the critical line so using an early version of Lindelöf we have that
$$|\zeta(1/2+it)|^2 \frac{1}{|-1/2+it|\times|1/2+it|} 
\in \mathcal{O}(|t|^{1/4\times 2-2}) = \mathcal{O}(|t|^{-3/2}).$$ 
and hence the integral converges absolutely. This shows that the remainder term from Mellin-Perron integral is
$$\mathcal{O}\left(\frac{1}{\sqrt{n}}\right)$$
Hence the final asymptotic expansion is in fact
$$q(n)-q(n-1) \sim
(n+1) \left(\frac{1}{2} \log^2 (n+1) + (2\gamma-1)\log (n+1) + (\gamma-1)^2 - 2\gamma_1 +
\mathcal{O}\left(\frac{1}{\sqrt{n+1}}\right)\right) \\
- n \left(\frac{1}{2} \log^2 n + (2\gamma-1)\log n + (\gamma-1)^2 - 2\gamma_1 +
\mathcal{O}\left(\frac{1}{\sqrt{n}}\right)\right)$$
which gives
$$\frac{1}{2} ((n+1)\log^2 (n+1) - n \log^2 n)
+ (2\gamma-1) ((n+1)\log (n+1) - n\log n) \\+  (\gamma-1)^2 - 2\gamma_1
+ \mathcal{O}\left(\sqrt{n+1}-\sqrt{n}\right).$$
Now expanding the asymptotics e.g. as in
$$(n+1)\log(n+1)-n\log n = \log(n+1) + n \log(1+1/n) =
\log n + (n+1)\log(1+1/n)$$
and in $\sqrt{n+1}-\sqrt{n} \sim \frac{1}{2\sqrt{n}}$
we see that the asymptotic expansion is indeed
$$\frac{1}{2} \log^2 n + 2\gamma\log n + \gamma^2 - 2\gamma_1 +
\mathcal{O}\left(\frac{1}{\sqrt{n}}\right).$$
Remark. I can probably do the sum for the odd integers restriction if anyone is interested.
A: Responding to the question regarding the weighted divisor sum over odd integers we use the same method as in the previous answer.
In the present case we have
$$\Lambda(s) = \left(1 - \frac{1}{2^{s+1}}\right)^2 \zeta(s+1)^2.$$
The corresponding residue is
$$\operatorname{Res}
\left(\Lambda(s) \frac{n^s}{s(s+1)}; s=0\right) = 
\frac{1}{8} \log^2 n
+ \left(\frac{\gamma}{2} - \frac{1}{4} + \frac{1}{2}\log 2\right) \log n \\
+ \frac{1}{4} (\gamma-1)^2
- \frac{1}{2} \gamma_1 + \gamma \log 2 - \frac{1}{2} \log 2.$$
Proceeding as in the previous post we obtain the following asymptotic expansion for the original sum:
$$\frac{1}{8} \log^2 n +
\left(\frac{\gamma}{2} + \frac{1}{2}\log 2\right) \log n +
\frac{\gamma^2}{4} + \gamma \log 2 - \frac{1}{2} \gamma_1
+ \mathcal{O}\left(\frac{1}{\sqrt{n}}\right).$$
The Mellin integral is absolutely convergent on the line $\Re(s) = -1/2$ because we have for the additional factor that
$$\left(1-\frac{1}{\sqrt{2}}\right)^2 
\le \left|\left(1-\frac{1}{2^{s+1}}\right)^2\right|
\le \left(1+\frac{1}{\sqrt{2}}\right)^2$$
(This is because the exponential term never changes its magnitude and just rotates as $t$ increases.)
Observation. It would seem an interesting challenge to verify these asymptotics numerically since both the sum itself and the integrals that appear exhibit very slow convergence.
A: I will do the case of the sum being restricted to even integers for the sake of completing the original problem as stated by the OP.
Start with $\Lambda(s)$ for $\sum_{n \; \text{odd}} d(n)/n^s$ which is
$$\Lambda(s) = \left(1-\frac{1}{2^s}\right)^2\zeta(s)^2.$$
It follows that for $\sum_{n \; \text{even}} d(n)/n^s$ we have
$$\Lambda(s) = \left(\frac{2}{2^s} + \frac{3}{2^{2s}} + \frac{4}{2^{3s}}
+ \cdots + \frac{k+1}{2^{ks}} + \cdots \right)
\left(1-\frac{1}{2^s}\right)^2\zeta(s)^2.$$
With the closed form of the sum we obtain
$$\Lambda(s) = \frac{1/2^s(2-1/2^s)}{(1-1/2^s)^2}
\left(1-\frac{1}{2^s}\right)^2\zeta(s)^2
= \frac{1}{2^s}\left(2-\frac{1}{2^s}\right)\zeta(s)^2.$$
It follows that the Dirichlet series for $\sum_{n \; \text{even}} d(n)/n/n^s$ is
$$\Lambda(s) =  \frac{1}{2^{s+1}}\left(2-\frac{1}{2^{s+1}}\right)\zeta(s+1)^2.$$
Now using the same technique as in the previous two cases we have
$$\operatorname{Res}
\left( \frac{1}{2^{s+1}}\left(2-\frac{1}{2^{s+1}}\right)\zeta(s+1)^2 
\frac{n^s}{s(s+1)}; s=0\right)= \frac{3}{8}\log^2 n \\
+ \left(\frac{3}{2}\gamma - \frac{1}{2}\log 2 - \frac{3}{4}\right) \log n
+ \frac{3}{4} (\gamma-1)^2 + \frac{1}{2}\log 2 -\gamma \log 2 - \frac{3}{2}\gamma_1.$$
Finally compute $q(n)-q(n-1)$ as in the previous two posts to get
$$\frac{3}{8}\log^2 n
+ \left(\frac{3}{2}\gamma - \frac{1}{2}\log 2\right) \log n
+ \frac{3}{4} \gamma^2 -\gamma \log 2 - \frac{3}{2}\gamma_1.$$
The remainder term is $\mathcal{O}(1/\sqrt{n})$ as before. What is very nice about this computation is that it is precisely the difference of the previous two results as predicted by Eric in his comment.
The Mellin integral converges because
$$ \frac{1}{\sqrt{2}} \left(2 - \frac{1}{\sqrt{2}}\right) \le
\left|\frac{1}{2^{s+1}}\left(2-\frac{1}{2^{s+1}}\right)\right| \le
 \frac{1}{\sqrt{2}} \left(2 + \frac{1}{\sqrt{2}}\right).$$ 
A: The asymptotic can be found using the hyperbola method.  Notice that $$\sum_{n\leq x}\frac{d(n)}{n}=\sum_{n\leq x}\frac{1}{n} \sum_{ab=n}1=\sum_{ab\leq x}\frac{1}{ab}.$$ Rearranging based on the geometry of the hyperbola, this equals $$2\sum_{a\leq\sqrt{x}}\frac{1}{a}\sum_{b\leq\frac{x}{a}}\frac{1}{b}-\sum_{a\leq\sqrt{x}}\sum_{b\leq\sqrt{x}}\frac{1}{ab}.$$ Since $\sum_{b\leq\frac{x}{a}}\frac{1}{b}=\log\frac{x}{a}+\gamma+O\left(\frac{a}{x}\right),$ it follows that  $$2\sum_{a\leq\sqrt{x}}\frac{1}{a}\sum_{b\leq\frac{x}{a}}\frac{1}{b}=2\sum_{a\leq\sqrt{x}}\frac{1}{a}\log\left(\frac{x}{a}\right)+2\gamma\sum_{a\leq\sqrt{x}}\frac{1}{a}+O\left(\frac{1}{x}\sum_{a\leq\sqrt{x}}1\right),$$ so we have that $$\sum_{n\leq x}\frac{d(n)}{n}=2\log x\sum_{a\leq\sqrt{x}}\frac{1}{a}-2\sum_{a\leq\sqrt{x}}\frac{\log a}{a}+2\gamma\left(\log\sqrt{x}+\gamma\right)-\left(\log\sqrt{x}+\gamma+O\left(\frac{1}{x}\right)\right)^{2}+O\left(\frac{1}{\sqrt{x}}\right)$$
$$=\frac{3}{4}\log^{2}x+2\gamma\log x-2\sum_{a\leq\sqrt{x}}\frac{\log a}{a}+\gamma^{2}+O\left(\frac{1}{\sqrt{x}}\right).$$ By definition of the Stieltjies constants, $$\sum_{a\leq z}\frac{\log a}{a}=\frac{\log^{2}z}{2}+\gamma_{1}+O\left(\frac{\log z}{z}\right),$$ so we obtain the asymptotic result $$\sum_{n\leq x}\frac{d(n)}{n}=\frac{1}{2}\log^{2}x+2\gamma\log x+\gamma^{2}-2\gamma_{1}+O\left(\frac{1}{\sqrt{x}}\right).$$ 
