<s>[INST] $1^2 + 2^2 + 3^2 + \cdots + (n-1)^2 \equiv 0$ mod n iff $n \equiv \pm 1$ mod 6 The problem is as follows: Prove that $$1^2 + 2^2 + 3^2 + \cdots + (n-1)^2 \equiv 0 \, \text{mod n} \ \text{if and only if } n \equiv \pm 1 \, \text{mod} 6.$$
My idea is to of course rewrite the summation. We have $$1^2 + 2^2 + 3^2 + \cdots + (n-1)^2 = \frac{(n-1)n(2n-1)}{6}.$$
Now, in order for this to be an integer, must we have in particular that $6 \mid n-1 \Rightarrow n \equiv 1 \, \text{mod} 6$?
We also know that the sum $$1^2 + 2^2 + 3^2 + \ldots + (n-1)^2 + n^2 = \frac{n(n+1)(2n+1)}{6}.$$ Must we have in particular that then $6 \mid n+1 \Rightarrow n \equiv -1 \, \text{mod} 6$?
I think the statement holds if and only if the whole way so we are done with both ways?
 [/INST] Hint: $6 \mid (n-1)(2n-1)$ implies that $n$ is odd and cannot be divisible by $3$.
</s>