How to solve $ \sum_{i=1}^{n-1} i^2 \equiv \;? \pmod n$ I solved expressions below . it is ok?
My attempt:
$$1)\;\;\;\;\; ?\cong\pmod n\sum_{i=1}^{n-1} i^2 \stackrel{?}=   {(n-1)^3\over3}+{(n-1)^2\over2}+{(n-1)\over6}={n^3\over3}-{n^2\over6}+{n\over6}=n\left({n^2\over3}-{n\over2}+{1\over6}\right)
 $$
(continue?)how to solve for all n?
$$2)\;\;\;\;\;?\cong\pmod n \sum_{i=1}^{n-1} i^3 = \left( {(n-1)n\over2} \right)^2$$
(continue?)how to solve for all n?
Thank you.

That problem, generalized to any exponent m instead of 2 is considered in the context of the Agoh-Giuga-conjecture, the perhaps most interesting articles about this are of Bernd Kellner, of the Borweins, and of WD Banks (all of them online available).       You might also consider to look at this earlier question at MSE of mine)
For the problem: 
$$ S_m(n) = \sum_{k=1}^{n-1} k^m \pmod n  $$
one can even heuristically arrive at the following formula:
$$ S_m(n) = n \cdot \sum_{\begin{array} {c} p | n \\ p-1 |m \end{array}} (1- \frac1p)  \pmod n $$
or, in this case
$$ S_2(n) = n \cdot \sum_{\begin{array} {c} p | n \\ p-1 |2 \end{array}} (1- \frac1p)  \pmod n $$
which, because $p=2$ and $p=3$ are the only prime where $p-1$ divides $2$
$$ S_2(n) = n\cdot ([n:3] \frac 23 + [n:2] \frac 12)   \pmod n $$
where I write $[a:b]$ for the Iverson-bracket, which evaluates to 1 if b divides a, and to zero, if not.

Here is some Pari/GP-code to work with this:

su(n)=n*(1/6 + 1/2*n + 1/3*n^2)  \\ by the known sum-formula 
                                 \\       from Bernoulli-polynomials
sumod(n) = su(n-1) % n           \\ taken modulo n

    \\ now the same by the primefactor-based formula 
sumod1(n) = ( (n % 3==0)*2*n/3 + (n % 2==0)*n/2 ) % n


\\ check this with some n
[n =8*74*3^2, sumod (n) ,  sumod1 (n)]

