Nếu \(n\)lẻ thì \(n=2k+1\)
\(n^2=\left(2k+1\right)^2=4k^2+4k+1=4k\left(k+1\right)+1\)
Có \(k\left(k+1\right)\)là tích hai số nguyên liên tiếp nên \(4k\left(k+1\right)⋮8\Rightarrow n^2\)chia cho \(8\)dư \(1\).
Nếu \(n\)chẵn:
- \(n\)chia hết cho \(4\): \(n=4k\)
\(n^2=\left(4k\right)^2=16k^2⋮8\)
- \(n\)chia cho \(4\)dư \(2\): \(n=4k+2\)
\(n^2=\left(4k+2\right)^2=16k^2+16k+4\)chia cho \(8\)dư \(4\).
Suy ra đpcm.