Lời giải:
Vì \(n^2+n+1\) là số chính phương nên đặt \(n^2+n+1=t^2\)
\(\Rightarrow 4n^2+4n+4=(2t)^2\)
\(\Leftrightarrow (2n+1)^2+3=(2t)^2\)
\(\Leftrightarrow (2t)^2-(2n+1)^2=3\)
\(\Leftrightarrow (2t-2n-1)(2t+2n+1)=3\)
TH1:
\(\left\{\begin{matrix} 2t-2n-1=1\\ 2t+2n+1=3\end{matrix}\right.\Rightarrow 2n+1=1\rightarrow n=0\)
TH2:
\(\left\{\begin{matrix} 2t-2n-1=3\\ 2t+2n+1=1\end{matrix}\right.\Rightarrow 2n+1=-1\rightarrow n=-1\)
TH3:
\(\left\{\begin{matrix} 2t-2n-1=-1\\ 2t+2n+1=-3\end{matrix}\right.\Rightarrow 2n+1=-1\rightarrow n=-1\)
TH4:
\(\left\{\begin{matrix} 2t-2n-1=-3\\ 2t+2n+1=-1\end{matrix}\right.\Rightarrow 2n+1=1\rightarrow n=0\)
Vậy \(n\in\left\{-1;0\right\}\)