-Xét \(n=3k\):
\(n^2+n+1=9k^2+3k+1\) chia 3 dư 1 (loại)
-Xét \(n=3k+1\):
\(n^2+n+1=\left(3k+1\right)^2+3k+1+1=9k^2+6k+1+3k+1+1=9k^2+9k+3\)
chia hết cho 3 (nhận)
-Xét \(n=3k+2\):
\(n^2+n+1=\left(3k+2\right)^2+3k+2+1=9k^2+12k+4+3k+2+1=9k^2+21k+7\)
chia 3 dư 1 (loại)
-Vậy \(n=3k+1\) (n chia 3 dư 1) thì \(n^2+n+1\) chia hết cho 3.