Prove that the square of an integer $a$ is of the form $a^2=3k$, or $a^2=3k+1$, where $k\in \mathbb{Z} $ Here's my attempt to prove this. I'm not sure about it, but i hope i'm correct.
Let $a=λ, λ\in \mathbb{Z}$. Then $a^2=λ^2=3\frac{λ^2}{3}$.
When $λ^2$ is divided by 3 there are three possible remainders $0,1,2$. So 
$$ λ^2=3k \lor λ^2=3k+1 \lor λ^2=3k+2   $$


*

*$ λ^2=3k \rightarrow a^2=3\frac{3k}{3}=3k $

*$ λ^2=3k+1 \rightarrow a^2=3\frac{3k+1}{3}=3k+1 $

*$ λ^2=3k+2 \rightarrow a^2=3\frac{3k+2}{3}=3k+2=3μ, μ\in \mathbb{Z} $


Therefore $$a^2=
 \begin{cases} 
      3k \\
      3k+1
   \end{cases}
$$
where $k$ is an integer.
Can someone verify this? Any help will be appreciated. Thanks in advance!
 A: By the division algorithm
\begin{equation}
x=3q+r, \quad r \in \{0, 1, 2\}
\end{equation}
writing
\begin{align}
x^{2} &= 9q^{2}+r^{2} +6qr \\
&= 3(3q^{2}+2qr)+r^{2}
\end{align}
The result follows if for a given $x$, $r=0, 1$. If $r=2$ then clearly $r^{2}=4=1+3$ and thus
\begin{align}
x^{2} &=3 \lambda + 1 + 3 \\
&= 3(\lambda + 1) +1
\end{align}
(I should make it clear that it is obvious why $\lambda$ is an integer)
Q.E.D
A: I don't understand how you eliminated the $3k+2 $ case. It might be easier just to look at the cases $a=3\lambda, a=3\lambda+1, a=3\lambda+2$ and multiply out. as follows:
When $a$ is divided by $3$, there are three possible remainders over an exact multiple of $3$: $0, 1,$ and $2$. Therefore consider the three cases 


*

*$a=3\lambda$

*$a=3\lambda+1$

*$a=3\lambda+2$ 


Then $a^2$ calculates out as follows:


*

*$a=3\lambda \implies a^2 = 9 \lambda^2 = 3(3 \lambda^2)$

*$a=3\lambda+1\implies a^2 = 9 \lambda^2 + 6\lambda + 1 = 3(3 \lambda^2 + 2\lambda)+1$

*$a=3\lambda+2\implies a^2 = 9 \lambda^2 + 12\lambda + 4 = 3(3 \lambda^2 + 6\lambda+1)+1$


giving a suitable value for $k$ in each case.
A: Hint
Use congruences, and the fact  that congruence are compatible with multiplication. Deides the three cases for congruence mod 3 can be written as $a\equiv 0,1,-1$.
