Compute $\left (1+\frac{1}{2}+\cdots+\frac{1}{n} \right )^2+\cdots+\left (\frac{1}{n-1}+\frac{1}{n} \right )^2+\left (\frac{1}{n} \right )^2$ Compute the value of the following expression
$$\left (1+\frac{1}{2}+\cdots+\frac{1}{n}  \right )^2+\left ( \frac{1}{2}+\cdots + \frac{1}{n}\right )^2+\cdots+\left (\frac{1}{n-1}+\frac{1}{n}  \right )^2+\left (\frac{1}{n}  \right )^2$$
The answer is $\boxed{2n-\left (1+\frac{1}{2}+\cdots+\frac{1}{n}  \right )}$.
I've been trying to do it but I've been failed. Any ideas ?
Wolfram's test
 A: $$S_n - S_{n-1} = n\times \left(\frac{1}{n}\right)^2 + 2\frac{1}{n}\left(1 \times \frac11 +2 \times \frac12+\cdots + (n-1)\times \frac{1}{n-1} \right) = 2-\frac1n$$ and $S_0$ can be taken to be $0$, so just add up $(S_n - S_{n-1})+(S_{n-1} - S_{n-2})+\cdots + (S_{1} - S_{0})$.
A: Using Iverson brackets and omitting the limits of sums when their index runs from $1$ to $n$, this is
$$
S_n=\sum_k\left(\sum_i\frac1i[k\leqslant i]\right)^2=\sum_{k}\sum_{i,j}\frac1{ij}[k\leqslant i,k\leqslant j]=\sum_{i,j}\frac1{ij}\sum_{k}[k\leqslant\min(i,j)]
$$
hence
$$
S_n=\sum_{i,j}\frac1{ij}\min(i,j)=\sum_{i,j}\frac1{\max(i,j)}=\sum_{m}\frac1m\sum_{i,j}[\max(i,j)=m]
$$
that is, as claimed by the OP,
$$
S_n=\sum_m\frac1m(2m-1)=2n-\sum_m\frac1m=2n-H_n
$$
A: We can solve this by recursion relations. Denoting the sum as $S_n$, we have,
$$ S_{n+1} = \left (1+\frac{1}{2}+\cdots+\frac{1}{n}+\frac{1}{n+1}  \right )^2+\left ( \frac{1}{2}+\cdots + \frac{1}{n} +\frac{1}{n+1}\right )^2+\cdots+\left (\frac{1}{n-1}+\frac{1}{n} +\frac{1}{n+1}  \right )^2+\left (\frac{1}{n} +\frac{1}{n+1}  \right )^2+\left (\frac{1}{n+1} \right)^2 = S_{n} +\frac {2}{n+1}(\left (1+\frac{1}{2}+\cdots+\frac{1}{n}  \right )+\left ( \frac{1}{2}+\cdots + \frac{1}{n}\right )+\cdots+\left (\frac{1}{n-1}+\frac{1}{n}  \right )+\left (\frac{1}{n}  \right ))+\sum_{k=1}^{n} \left (\frac{1}{n+1} \right)^2 +\left (\frac{1}{n+1} \right)^2 = S_{n} + \frac{2n+1}{n+1} $$
So, we have $$S_{n} - S_{n-1} = \frac {2n-1}{n}=2-\frac{1}{n}$$
Where from we get,
$$S_{n}-S_{1} = 2n - 1 -\left (1+\frac{1}{2}+\cdots+\frac{1}{n}  \right )$$
But $S_{1} = 1$. So,
$$S_{n} = 2n  -\left (1+\frac{1}{2}+\cdots+\frac{1}{n}  \right )$$
A: You can prove the claim by induction. For $n=1$ you have $1=1$ which is clearly true.
For $n+1$ you can compute
$$
\left(1+\frac{1}{2}+\ldots+\frac1n+\frac{1}{n+1}\right)^2 + \left(\frac{1}{2}+\ldots+\frac1n+\frac{1}{n+1}\right)^2 + \ldots + \left(\frac{1}{n}+\frac{1}{n+1}\right)^2 + \left(\frac{1}{n+1}\right)^2
$$
using the binomial theorem as
$$
\left(1+\frac{1}{2}+\ldots+\frac1n\right)^2 + \frac{2}{n+1}\left(1+\frac{1}{2}+\ldots+\frac1n\right)+\left(\frac{1}{n+1}\right)^2+\\ + \left(\frac{1}{2}+\ldots+\frac1n\right)^2 + \frac{2}{n+1}\left(\frac{1}{2}+\ldots+\frac1n\right)+\left(\frac{1}{n+1}\right)^2+\\+\ldots+\\+\left(\frac1{n}\right)^2+\frac{2}{n+1}\frac1n+\left(\frac1{n+1}\right)^2+\\+\left(\frac1{n+1}\right)^2
$$
The first terms in each row (except the last) can be collectively computed used the induction hypothesis as 
$$
2n-\left(1+\frac12+\ldots+\frac1n\right);
$$
the last terms from each row (including the last) give 
$$
(n+1)\left(\frac{1}{n+1}\right)^2=\frac{1}{n+1}.
$$ 
The middle terms give 
$$
\frac{2}{n+1}\left(1+\left[\frac12+\frac12\right] + \ldots +\left[\frac1n + \ldots + \frac1n\right] \right) = \frac{2}{n+1}\left(n\times 1\right) = 2\frac n{n+1}.
$$
In total we thus obtain
$$
2n-\left(1+\frac12+\ldots+\frac1n\right) + 2\frac n{n+1} + \frac{1}{n+1}\\ = 2n-\left(1+\frac12+\ldots+\frac1n\right) + \frac {2n+1}{n+1}\\=2n-\left(1+\frac12+\ldots+\frac1n\right) + \frac {2(n+1)-1}{n+1}\\=2n-\left(1+\frac12+\ldots+\frac1n\right) + \frac {2n+1}{n+1}\\=2(n+1)-\left(1+\frac12+\ldots+\frac1n+\frac{1}{n+1}\right),
$$
from which the claim follows.
