[Math] Prove that if $n$ is a perfect square, then either $n \equiv 1 \pmod 4$, or $n \equiv 0 \pmod 4$.

integersmodular arithmeticproof-writing

An integer $n$ is a perfect square if and only if it can be expressed as the square of some other integer i.e. there exists some integer $a$ such that $n=a^2$.

Prove that if $n$ is a perfect square, then either $n \equiv 1 ~(\mod 4)$, or $n \equiv 0 ~(\mod 4)$.

How can I prove this?

Best Answer

Suppose $a = 2k$, for some integer k, and $n = a^2=4k^2$ which is zero mod 4. Otherwise, a is odd, and $a = 2k+1$. Then $n = a^2=(2k+1)^2=4k^2+4k+1= 4(k^2+k)+1$. This is 1 mod 4. This is desired result.

Related Question