>Added 14/04/17: So I am placing a bounty on this question because I am very interested in knowing about strategies for calculating the asymptotic behaviour of this sum. I have calculated $S(X)$ for $X<10^8$ and I am fairly confident that we have $S(X)\sim X/2$. Alas this doesn't prove anything yet though. Can this be proved? Due to the lack of answers, I suppose this is a hard problem, so I would also accept answers that can make this clear in some way. For instance, if solutions to this sort of problem depend on the solution of some open problem or the resolution of a conjecture which lies deep, then an explanation would be welcome. It is not clear to me what the level of difficulty of this problem is but it appears to involve questions about notions of randomness in number theory, and so it seems like a reasonable MO question. The motivation here comes from considering the Dirichlet series $$\sum_1^{\infty}\frac{d(n)}{n^s}\sum_{q|n-1:q\leq X}1,$$ and looking at the value of (the analytic continuation of-) this function at $s=0$. Such Dirichlet series are related to questions about the autocorrelation of the divisor function, for which the asymptotics were worked out by Ingham and Estermann in the 1920's and 1930's. The objective is to obtain an asymptotic formula for the sum $$S(X)=\sum_{q\leq X}\frac{1}{\phi(q)}\sum_{\chi}L^2(0,\chi),$$ and it can easily be shown that determining this is equivalent to knowing something interesting about Farey fractions. It is fairly elementary that \begin{eqnarray}\label{} S(X)=\sum_{q\leq X}\frac{1}{\phi(q)}\sum_{\chi} \left( \sum_{a\leq q} \chi(a)\zeta\left(0 ,\frac{a}{q}\right) \right)^2 \end{eqnarray} where $\zeta(s,a)$ is the Hurwitz zeta function so, denoting by $a^*$ the multiplicative inverse of $a$ modulo $q$, expanding out the square and using the orthogonality relations for the Dirichlet characters one obtains $$S(X)=\sum_{q\leq X}\sum_{(a,q)=1}\left(\frac{a}{q}-\frac{1}{2}\right)\left(\frac{a^*}{q}-\frac{1}{2}\right).$$ Noting that the mean value of the non-trivial Farey fractions ($0$ and $1$ being trivial) is $1/2$ for all $X$, at this point one probably realises that $S(X)/X^2$ is proportional (by a factor of $3/\pi^2$) to the correlation of the non-trivial Farey fractions of order $X$ with their multiplicative inverses modulo their denominators. Since one would expect the values of $a/q$ and $a^*/q$ to be independent as $q\rightarrow\infty$, one would expect that $$S(X)=O(X^{1+\epsilon})$$ and so I would like to pose the following question: >Can an asymptotic formula for $S(X)$ be determined, or just a non-trivial upper or lower bound, via the Farey fractions or the Dirichlet L-functions? Potentially, one way to proceed is to multiply out the product and use the symmetry about $1/2$ to obtain $$S(X)=-\frac{1}{2}+\sum_{q\leq X}\sum_{(a,q)=1}\left(\frac{aa^{*}}{q^2}-\frac{1}{4}\right).$$ Using the fact that $aa^{*}-k(a)q=1$, where $k(a)$ is the greatest number of integer multiples of $q$ less than $aa^{*}$, and $k(a)/q$ is another non-trivial Farey fraction, one obtains $$S(X)=-\frac{1}{2}+\sum_{q\leq X}\sum_{(a,q)=1}\left(\frac{k(a)}{q}-\frac{1}{4}\right) +O(\log X).$$ However, the mapping $a\rightarrow k(a)$ is not an automorphism of the multiplicative group of integers modulo $q$, and the behaviour of $k$ seems to be quite complex. >Added 14/04/17: I should also mention that it appears that even the strongest conjectures on bounds on sums of Kloosterman sums (e.g. of Selberg type) seem to be of little utility here.