<s>[INST] Sum of greatest common divisors As usually, let $\gcd(a,b)$ be the greatest common divisor of integer numbers $a$ and $b$.
What is the asymptotics of
$$\frac{1}{n^2} \sum_{i=1}^{i=n} \sum_{j=1}^{j=n} \gcd(i,j)$$
as $n \to \infty?$
 [/INST] We can rewrite the sum as 
$$
\begin{align}
S(n)&=\frac{1}{n^2}\sum_{i=1}^n\sum_{j=1}^n\gcd(i,j) \\ &= \frac{1}{n^2}\sum_{g=1}^n\sum_{i\le\lfloor n/g\rfloor}\sum_{\substack{j\le\lfloor n/g\rfloor\\(i,j)=1}} g \\
&= \frac{1}{n^2}\sum_{g=1}^n g\left(-1+2\sum_{i=1}^{\lfloor n/g\rfloor} \varphi(i)\right) \\
&= -\frac{n(n+1)}{2n^2}+\frac{2}{n}\sum_{g=1}^n \frac{g}{n}\sum_{i=1}^{\lfloor n/g\rfloor} \varphi(i)
\end{align}
$$
Write
$$
f(x) = \frac{1}{x}\sum_{i\le x}\varphi(i) = \frac{3x}{\pi^2}+E(x) \\
E(x) = o(\log x)
$$
(see Eric Naslund's exposition) then
$$
\begin{align}
S(n) &= -\frac{1}{2}-\frac{1}{2n}+\frac{2}{n}\sum_{g=1}^{n}f(n/g) \\
&= -\frac{1}{2}-\frac{1}{2n}+\frac{6}{\pi^2}\sum_{g=1}^{n}\frac{1}{g}+\frac{2}{n}\sum_{g=1}^n E(n/g) \\
&= \frac{6}{\pi^2}\log n+\frac{6\gamma}{\pi^2}-\frac{1}{2}+C+o(1) \\
&= \frac{6}{\pi^2}\log n + C' + o(1)
\end{align}
$$
where the constant $C$ arises from
$$
E(x) = o(\log x) \\
\left|\frac{2}{n}\sum_{g=1}^n E(n/g)\right|< \frac{C}{n}\sum_{g=1}^n\log(n/g)=C\left(\log n - \frac{\log n!}{n}\right)=C+o(1)
$$
by Stirling's approximation. Calculations suggest $C=0.39344\cdots, C'=0.24434\cdots$.
</s>