This is a question from the free Harvard online abstract algebra lectures. I'm posting my solutions here to get some feedback on them. For a fuller explanation, see this post.

This problem is from assignment 6. The notes from this lecture can be found here.

a) Prove that the square $a^2$ of an integer $a$ is congruent to 0 or 1 modulo 4.
b) What are the possible values of $a^2$ modulo 8?

a) Let $a$ be an integer. Then $a=4q+r, 0\leq r<4$ with $\bar{a}=\bar{r}$. Then we have $a^2=a\cdot a=(4q+r)^2=16q^2+8qr+r^2=4(4q^2+2qr)+r^2, 0\leq r^2<4$ with $\bar{a^2}=\bar{r^2}$. So then the possible values for $r$ with $r^2<4$ are 0,1. Then $\bar{a^2}=\bar{0}$ or $\bar{1}$.

b) Let $a$ be an integer. Then $a=8q+r, 0\leq r<8$ with $\bar{a}=\bar{r}$. Then we have $a^2=a\cdot a=(8q+r)^2=64q^2+16qr+r^2=8(8q^2+2qr)+r^2, 0\leq r^2<8$ with $\bar{a^2}=\bar{r^2}$. So then the possible values for $r$ with $r^2<8$ are 0,1,and 2. Then $\bar{a^2}=\bar{0}$, $\bar{1}$ or $\bar{4}$.

Again, I welcome any critique of my reasoning and/or my style as well as alternative solutions to the problem.


  • 2
    $\begingroup$ In (a), I don't think, unless you're changing your definition of $r$ in the middle, that $r^2<4$ is necessarily true. Suppose $a=3$ so that $q=0$ and $r=3$—shouldn't $r^2=9$? $\endgroup$ – Isaac Jan 17 '12 at 0:08
  • $\begingroup$ Your reasoning for a) is slightly flawed, as we need not have $r^2<4$. Consider for example $a=3$, then $r^2=9$. But we can observe that $\bar{r^2}=1$. $\endgroup$ – Alex Becker Jan 17 '12 at 0:09
  • $\begingroup$ Seems I was not the only one to observe that though. $\endgroup$ – Alex Becker Jan 17 '12 at 0:10
  • $\begingroup$ Perhaps a little too abstract for my taste. Maybe also not absolutely clear from solution that mod $8$, all of $0$, $1$, and $4$ are actually achievable. Also, there are little mistakes, for example we definitely do not have $r^2<8$. $\endgroup$ – André Nicolas Jan 17 '12 at 0:20
  • 3
    $\begingroup$ It would help if you could provide precise links to the notes and exercises you are using. I could not find such based on the link you gave. $\endgroup$ – Bill Dubuque Jan 17 '12 at 0:39

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!


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.

  • $\begingroup$ Indeed $\rm\ mod\ 4\!:\ even^2\equiv \{0,\:2\}^2\equiv 0,\ \: odd^2\equiv \{1,\:3\}^2\equiv \{\pm 1\}^2 \equiv 1\:.$ Similarly $\rm\:mod\ 8\:,\:$ see my answer. $\ $ $\endgroup$ – Bill Dubuque Jan 17 '12 at 3:20

HINT $\: $ Division $\rm\Rightarrow n = 4\ q + r,\ r\in \{0\ 1\ 2\ 3\}\Rightarrow n^2 = (4\:q+r)^2 =$ $\rm\: 4\:(4\:q^2+2\:q\:r)+r^2 = $ $\rm\:4\:Q + r^2\:.\:$ Now for $\rm r\in \{0\ 1\ 2\ 3\}$ compute $\rm\: r^2 = 4\ \bar q + \bar r\ \Rightarrow\ n^2 = 4\ (Q+\bar q) + \bar r,\ \ \bar r\in \{0\ 1\ 2\ 3\}\:.$

Expressed in modular language it's simpler: $\rm\ mod\ 4\!:\ n\equiv r\ \Rightarrow\ n^2 \equiv r^2\equiv \{0\ 1\ 2\ 3\}^2\ $ by applying the congruence product rule, or knowledge of quotient / residue ring $\rm\ \mathbb Z/4\ =\ \mathbb Z\ mod\ 4\:.$

Optimization: work is halved employing a balanced residue system, e.g. $\rm\: \pm \{0,1,2,3,4\}\ mod\ 8\:.\ $ Using that we quickly compute $\rm\ mod\ 8\!:\ odd^2\equiv \{ 1, \: 3\}^2 \equiv 1,\ \: even^2 \equiv \{0,\: 2,\: 4\}^2 \equiv \{0,\: 4\}\:.$


$$\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} $$

  • 1
    $\begingroup$ Welcome to math.SE! For some basic information about writing math at this site see e.g. here, here, here and here. $\endgroup$ – user642796 Oct 1 '13 at 9:10

The glitch I am going to point out is not very serious, though keeping tracking of such things helps.

For instance, in (a), how is $0\leq r^2<4$. Consider a number of the form $4q+2$, you'll have an issue. But, however, what follows this error, $\bar a^2=\bar r^2$ is correct. But Why? Because, the the remainder when $ a^2$ is divided by $4$ is the same as that when $ r^2$ is divided by $4$ is what the equation reads and what you have proved.

So, to really complete the solution, you need to take a case-by-case approach. For various possible values of $r$, prove that $\bar r^2$ is as claimed.

Remark: It is an equivalence that $a=4q+r, 0\leq r<4 \iff \bar a=\bar r$. So, your statement that, "[...]Then $a=4q+r,0 \leq r<4~ \text {with}~ \bar a=\bar r$[...]" is a little clumsy.

The same remarks go for (b).

Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.