$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?
 A: For the proof, we use the following observations:
(i) Suppose that $n$ divides $\frac{(n-1)(n)(2n-1)}{6}$. Then 
$6n$ divides $(n-1)(n)(2n-1)$, and therefore $6$ divides $(n-1)(2n-1)$.  
(ii) Conversely, if $6$ divides $(n-1)(2n-1)$, then $6n$ divides $(n-1)(n)(2n-1)$, and therefore  $n$ divides $\frac{(n-1)(n)(2n-1)}{6}$.

We first show that if $\gcd(n,6)\gt 1$, then $6$ cannot divide $(n-1)(2n-1)$.
This is obvious if $n$ is even, since then $n-1$ and $2n-1$ are odd. So suppose that $3$ divides $n$.  Then $3$ cannot divide $n-1$ or $2n-1$.
We have shown that if $1^2+2^2+\cdots+(n-1)^2$ is divisible by $n$, then $n$ and $6$ must be relatively prime, and therefore $n\equiv \pm 1\pmod{6}$.

Next we show that if $n\equiv \pm 1\pmod{6}$, then $6$ divides $(n-1)(2n-1)$. This is obvious if $n\equiv 1\pmod{6}$. 
If $n\equiv -1\pmod{6}$, then $2n\equiv -2\pmod{6}$, and therefore $2n-1\equiv -3\pmod{6}$, and therefore $3$ divides $2n-1$. Moreover, $n$ is odd, so $n-1$ is even, and therefore $6$ divides $(n-1)(2n-1)$.   
A: Hint: $6 \mid (n-1)(2n-1)$ implies that $n$ is odd and cannot be divisible by $3$.
A: $n|\sum\limits_{k=1}^{n-1}k^2\iff n|\frac{n\cdot(n-1)\cdot(2n-1)}{6}$
$\iff 6|(n-1)\cdot(2n-1)$
$\impliedby n\equiv 1\pmod 6$ 
If $n\not\equiv 1 \pmod 6$, then since $(2n-1)$ is odd, $n\equiv 1\pmod 2\, \&\, 2n\equiv 1\pmod 3$
i.e., $n\equiv-1\pmod 2 \,\&\, n\equiv -1\pmod 3\implies n\equiv -1 \pmod 6$.
