The square of an integer has form $3n$ or $3n+1$ Prove that if $n\in\mathbb Z$, then $n^2$ is of the form $3q$ or $3q+1$ for some $q\in\mathbb Z$
I would like to show that 3q+2 is = 3q+1 thus $n^2$ can be of the form of 3q or 3q+1.
Case one 
$(3k)^2=(3k)(3k)=9k^2=3(3k^2)$ and is still of the form $3q$
When $q=3k^2$
$3q$
Case two
$(3k+1)^2= (3k+1)(3k+1)= 9k^2+6k+1$
$(9k^2+6k)+1 =3(3k^2+2k)+1$
this is of the form $3q+1$ when $q=3k^2+2k$
$3q+1$
Case three
$(3k+2)^2= (3k+2)(3k+2) =9k^2+12k+4$
$(9k^2+12k+4) = 3(3k^2+4k+1)+1$
This is of the form $3q+1$ when $q=3k^2+4k+1$
$3q+1$
using a direct proof with cases we see that when $n$ is of the form $3k$ it's in the form $3q$ after squaring. Also when n is in the form $3k+1$, $n$ squared is still in the form $3q+1$ after squaring. Lastly we saw that when $n$ was in the form $3k+2$ we could simplify to the form $3q+1$.

Proof is easy ($k \in Z$)
1) if $n = 3k$, $n^2 = 9k^2$, QED
2) if $n = 3k + 1$, then $n^2 = 3kn + n = 3kn + 3k + 1$, QED
3) if $n = 3k + 2$, then $n^2 = 3kn + 2n = 3kn + 6k + 3 + 1$, QED
