به نام خدا.
این راه را من از آقای @AmirHosein در یکی از پرسشهایم آموختم.
عدد $n$ باقیماندهاش بر $7$ باید یکی از اعداد $1,2,\dots,6$ باشد. پس عدد $n^2$ باقیماندهاش بر $7$ میشود:
$n \equiv 1(\text{mod}7) \Longrightarrow n^2 \equiv 1 (\text{mod}7)$
$n \equiv 2(\text{mod}7) \Longrightarrow n^2 \equiv 4(\text{mod}7)$
$n \equiv 3(\text{mod}7) \Longrightarrow n^2 \equiv 2(\text{mod}7)$
$n \equiv 4(\text{mod}7) \Longrightarrow n^2 \equiv 2(\text{mod}7)$
$n \equiv 5(\text{mod}7) \Longrightarrow n^2 \equiv 4(\text{mod}7)$
$n \equiv 6(\text{mod}7) \Longrightarrow n^2 \equiv 1(\text{mod}7)$