Solution (source code)

= Solution

In the multiplicative <group> $\mathbb F_p^\times$, the squaring map is a <group homomorphism> with kernel $\{1,-1\}$, since $p$ is odd. Every nonzero square therefore has exactly two square roots. There are $(p-1)/2$ <quadratic residues> and the same number of nonresidues, and consequently $\sum_{a=1}^{p-1}\left(\frac ap\right)=0$.

For $nm_n\equiv1\pmod p$, direct multiplication gives $n^2(1+m_n)\equiv n^2+n=n(n+1)$. Multiplicativity of the <Legendre symbol>, including its value zero on multiples of $p$, implies
$$
\left(\frac{n(n+1)}p\right)=\left(\frac{1+m_n}p\right).
$$
Inversion permutes $\mathbb F_p^\times$, so $1+m_n$ runs through all residue classes except $1$. Thus
$$
\boxed{\sum_{n=1}^{p-1}\left(\frac{n(n+1)}p\right)=\sum_{a\in\mathbb F_p,\ a\ne1}\left(\frac ap\right)=0-1=-1.}
$$