The square of an integer is congruent to 0 or 1 mod 4

Suppose the integer $z$ is even. Write it as $z = 2n$, where $n\in\mathbb{Z}$. Then $z^2 = 4n^2$; $z$ is divisible by 4. Suppose the integer $z$ is odd. Write it as $z = 2n + 1$ where $n\in\mathbb{Z}$; then $z^2 = 4n^2 + 4n + 1 = 4n(n+1) + 1.$

We have just shown that for any integer $z$, the square of $z$, when divided by 4 gives remainder 1 or 0.


For the first one the idea of what you have done is right (although did you mean to say that since $0 \leq r < 4$, $0 \leq r^2 < 16$?). An alternative viewpoint is to look at it like this. Define an equivalence relation $\sim$ on the integers by $x\sim y$ iff $x - y $ is a multiple of $4$. Then you can check that this is an equivalence relation, so that you know every integer in the universe is of the form $4k$, $4k+1$, $4k+2$, or $4k+3$. This is basically the division algorithm.

If you square each one of these, the first one is $16k^2 \equiv 0 $ mod $4$, the second is congruent to 1 mod 4, the third is congruent to zero mod 4 because $2^2 = 4$ and the last is congruent to 1 mod 4 because $(4k+3)^2 = 4(\text{stuff}) + 1$.

The second problem is a casebash too (just this time you're working mod 8 as you have done).

Alternatively, there is another way to look at this in terms of group theory. I'm mentioning this because you are studying groups and one way or another you will come to this. Consider the integers $\mathbb{Z}$ as a group. For question (a), let $\pi$ be the canonical projection from $\mathbb{Z}$ to $\mathbb{Z}/(4)$, where $(4)$ is the cyclic normal subgroup of $\mathbb{Z}$ consisting of all the multiples of $4$. $\pi$ is a map that sends each integer to its equivalence class, where the equivalence relation here is

$$x \sim y \hspace{3mm} \text{iff} \hspace{3mm} x - y \in (4).$$

Let us write $[a]$ for the equivalence class of an integer in the quotient $\mathbb{Z}/(4)$. Now multiplication in the quotient is well-defined because $(4)$ is a normal subgroup, so that $[a \times a] = [a] \times [a]$. There is no ambiguity in using $\times$ for both as it is just ordinary multiplication of integers.

What this means is when looking at the possible remainders of the square of an integer mod 4, you can just concentrate on calculating

$$ \begin{eqnarray} 0^2 &\equiv& 0 \hspace{2mm} \text{mod} \hspace{2mm} 4\\ 1^2 &\equiv& 1 \hspace{2mm} \text{mod} \hspace{2mm} 4 \\ 2^2 &\equiv& 0 \hspace{2mm} \text{mod} \hspace{2mm} 4\\ 3^2 &\equiv& 1 \hspace{2mm} \text{mod} \hspace{2mm} 4. \end{eqnarray}$$ This is because given any integer $[a]$, $[a] = [0],[1],[2]$ or $[3]$. Similarly for (b) your problem reduces to calculating the squares of $0,1,2 \ldots 7$ mod $8$.

Hope this helps!


$$\begin{align} x^2 \mod 4 &\equiv (x \mod 4)(x \mod 4) \pmod 4 \\ &\equiv \begin{cases}0^2 \mod 4 \\ 1^2 \mod 4 \\ 2^2 \mod 4 \\ 3^2 \mod 4 \end{cases} \\ &\equiv \begin{cases}0 \mod 4 \\ 1 \mod 4 \\ 4 \mod 4 \\ 9 \mod 4 \end{cases} \\ &\equiv \begin{cases}0 \mod 4 \\ 1 \mod 4 \\ 0 \mod 4 \\ 1 \mod 4 \end{cases} \end{align} $$