<s>[INST] Interesting determinant: Let $A$ be an $n$ by $n$ matrix with entries $a_{i,j}$ given that $a_{i,j}=2$ if $i=j$ Let $A$ be an $n$ by $n$ matrix with entries $a_{i,j}$ given that $a_{i,j}=2$ if $i=j$, $a_{i,j}=1$ if $i-j\equiv\pm2\pmod n$, and $a_{i,j}=0$ otherwise.
Find $\det A$.

It seems that the determinant is 4 for all odd $n$. What about even $n$?
 [/INST] Note that we have the degenerate cases $n=1, 2, 4$, where there are less than $3$ non-zero elements in each row/column. 
When $n=1, 2, 4$ respectively, we get $\det(A)=2, 4, 9$.
Let us now consider $n \not =1, 2, 4$, so that each row/column has one $2$ and two $1$s and no other non-zero element. 
Observe that $A$ is a circulant matrix, for which the determinant is easy to compute.
We may verify that $A$ has eigenvectors 
$$\begin{pmatrix} 1 \\ \omega^j \\ \omega^{2j} \\ \ldots \\ \omega^{(n-1)j} \end{pmatrix}$$
for each $j=0, 1, \ldots , n-1$ where $\omega=e^{\frac{2  \pi i}{n}}$ is a $n$th root of unity. The corresponding eigenvectors are $2+\omega^{2j}+\omega^{(n-2)j}$.
Now the $n$ eigenvectors given above ($j=0, 1, \ldots , n-1$) are exactly the roots of the characteristic polynomial of $A$, so 
$$\det(A-tI)=\chi_A(t)=(-1)^n\prod_{j=0}^{n-1}{(t-(2+\omega^{2j}+\omega^{(n-2)j}))}$$
Putting $t=0$ gives 
\begin{align}
\det(A)& =\prod_{j=0}^{n-1}{(2+\omega^{2j}+\omega^{(n-2)j})} \\
&=\prod_{j=0}^{n-1}{(\omega^j+\omega^{-j})^2} \\
&=4\prod_{j=1}^{n-1}{(\omega^j+\omega^{-j})^2} \\
&=4\prod_{j=1}^{n-1}{\omega^{-2j}}\prod_{j=1}^{n-1}{(\omega^{2j}+1)^2} \\  
&=4\omega^{-(n-1)n}\left(\prod_{j=1}^{n-1}{(\omega^{2j}+1)}\right)^2 \\
&=4\left(\prod_{j=1}^{n-1}{(\omega^{2j}+1)}\right)^2
\end{align}
It remains to compute $\prod_{j=1}^{n-1}{(\omega^{2j}+1)}$.
Notice that if $n$ is odd, then $\omega^2, \omega^4, \ldots , \omega^{2(n-1)}$ are simply $\omega, \omega^2, \ldots , \omega^{n-1}$ in some order. Furthermore, we know that $\omega^j$ are the roots of $\frac{x^n-1}{x-1}=x^{n-1}+\ldots +x+1$, so $$x^{n-1}+\ldots +x+1=\prod_{j=1}^{n-1}{(x-\omega^j)}$$
Putting $x=-1$ then gives 
$$1=\prod_{j=1}^{n-1}{(-1-\omega^j)}=(-1)^{n-1}\prod_{j=1}^{n-1}{(1+\omega^j)}=(-1)^{n-1}\prod_{j=1}^{n-1}{(1+\omega^{2j})}$$
Thus when $n$ is odd, $\det(A)=4$.
When $n=2m$ is even, we have 
$$\prod_{j=1}^{n-1}{(1+\omega^{2j})}=2\left(\prod_{j=1}^{m-1}{(1+\omega^{2j})}\right)^2$$
Now $\omega^{2j}$ are roots of $x^{m-1}+ \ldots +x+1$, so 
$$x^{m-1}+ \ldots +x+1=\prod_{j=1}^{m-1}{(x-\omega^{2j})}$$
Putting $x=-1$ gives $$(-1)^{m-1}\prod_{j=1}^{m-1}{(1+\omega^{2j})}= \begin{cases} 1 & 2 \nmid m \\ 0 & 2\mid m \end{cases}$$
Thus $$\det(A)=4\left(2\left(\prod_{j=1}^{m-1}{(1+\omega^{2j})}\right)^2\right)^2=\begin{cases} 16 & 2\nmid m \\ 0 & 2 \mid m \end{cases}$$
All in all,
$$\det(A)= \begin{cases} 2 & n=1 \\ 4 & n=2 \\ 9 &n=4 \\ 4 & 2 \nmid n, n>1\\ 16 & n \equiv 2 \pmod{4}, n>2 \\ 0 & 4 \mid n, n>4 \end{cases}$$
</s>