Hint: Given any integer n, begin by using the quotientremainder
theorem to say that n can be written in
one of the three forms: n = 3q, or n = 3q + 1, or
n = 3q + 2 for some integer q. Then divide into three
cases according to these three possibilities. Show that
in each case either n2 = 3k for some integer k, or
n2 = 3k + 1 for some integer k. For instance, when
n = 3q + 2, then n2 = (3q + 2)2 = 9q2 + 12q + 4 =
3(3q2 + 4q + 1) + 1, and 3q2 + 4q + 1 is an integer
because it is a sum of products of integers.