For every n∈Z, you have three possible cases (where k∈Z):

n = 3k (divisible by 3 with no remainder)

n = 3k+1 (leaves a remainder of 1 when divided by 3)

n = 3k+2 (leaves a remainder of 2 when divided by 3)

Let us consider the square of each of these cases separately:

If n = 3k, then n² = (3k)² = 3(3k²) --> If n is divisible by 3, the square is also divisible by 3.

If n = 3k+1, then n² = (3k+1)² = 9k²+6k+1 = 3(3k²+2k) + 1 --> The square is NOT divisible by 3.

If n = 3k+2, then n² = (3k+2)² = 9k²+12k+4 = 3(3k²+4k+1) + 1 --> The square is NOT divisible by 3.

If the number is divisible by 3, then the square is divisible by 3.

If the square is divisible by 3, that only happens if the original number was divisible by 3.

So we have shown the number is divisible by 3 *if and only if* the square is divisible by 3.

Q.E.D.