Doubt in Proof of Dirichlet Asymptotic formula for partial sum of divisor function $d(n)$

analytic-number-theorynumber theory

I am studying Analytic number theory from Tom M Apostol Introduction to analytic number theory and I have doubt in the proof given in the book.

Dirichlet gives two proof of formula
1 st has error term $O(x)$ and I don't have any doubt in it.

I have doubt in his 2nd proof where he deduces error term to be $(2C-1) x +O(\sqrt{x})$. He writes before giving the argument of Lattice Points that we take advantage of symmetry of region about $q=d$. The total number of lattice points in region is equal to twice the number below line q=d plus the number of bisecting line segments.
I don't understand how apostol derives the formula which I am mentioning in the image along with the diagram.

enter image description here

Can somebody please tell how to derive this formula.

Best Answer

$$\sum_{n\le x} d(n)= \sum_{n\le x}\sum_{md=n}1=\sum_{md\le x}1= 2\sum_{md\le x,d<m} 1+ \sum_{d^2\le x} 1=2\sum_{d<\sqrt{x}}(\lfloor x/d\rfloor -d) + \lfloor \sqrt{x}\rfloor$$ In the figure : $ \lfloor \sqrt{x}\rfloor$ is the number of lattice point on the diagonal,

$\lfloor x/d\rfloor -d$ is the number of lattice points with abscissa $d$ and on the right side of the diagonal (the horizontal segment plotted in the black region)

The asymptotic is immediate from there since $\lfloor x/d\rfloor = x/d+O(1)$

Related Question