# Math Help - For which n is 1^2 + 2^2 + ... + (n-1)^2 ≡ 0 mod n true?

1. ## For which n is 1^2 + 2^2 + ... + (n-1)^2 ≡ 0 mod n true?

For which n ≥ 2 is the following true; 1^2 + 2^2 + ... + (n-1)^2 ≡ 0 mod n

I've tried some numbers and found that it works for 5 but I'm not exactly sure why that is.

I'm aware of that 1^2 + 2^2 + ... + (n-1)^2 is the sum of every element in complete residue system for n multiplicative by itself and that I need to find out when there's a factor n in this sum but I'm honestly pretty stuck. Can anyone perhaps help me out?

2. ## Re: For which n is 1^2 + 2^2 + ... + (n-1)^2 ≡ 0 mod n true?

It might help to use the well known sum \displaystyle \begin{align*} \sum_{k = 1}^{n} k^2 = \frac{n(n + 1)(2n+1)}{6} \end{align*}, or equivalently \displaystyle \begin{align*} \sum_{k = 1}^{n - 1}k^2 = \frac{(n - 1)(n)(2n - 1)}{6} \end{align*}.