<s>[INST] Find determinant of an almost diagonal matrix except first row and column $$\begin{vmatrix}
0 & 1  & 1  &  & 1\\
1  & a_1 &   &  & \\
1  &   & a_2 &  & \\
\vdots &  &  & \ddots & \\
1  &  &  & & a_n
\end{vmatrix}$$
If I suppose $a_1,\dots ,a_n\ne0$, I know how to do it, multiply the $i$-th column by $-1/a_i$ and add to the first column. Doing that I get the correct solution $ -a_1a_2 ...a_n(1/a_1+...+1/a_n)$.
How to avoid the zero case ?
 [/INST] If $a_k = 0$, then we row expand on $(k+1)^\text{th}$ row and we get:
$$\left|
\begin{matrix}
0 & 1 & 1 & \cdots & 1 & 1 & 1 &\cdots & 1 \\
1 & a_1 & 0 & \cdots & 0 & 0 & 0&\cdots & 0 \\
1 & 0 & a_2 & \cdots & 0 & 0 & 0&\cdots & 0 \\
\vdots & & & \ddots & & & & & \vdots \\
1 & 0 & 0 & \cdots & a_{k-1} & 0 & 0 &\cdots & 0 \\
1 & 0 & 0 & \cdots & 0 & a_k & 0 &\cdots & 0 \\
1 & 0 & 0 & \cdots & 0 & 0 & a_{k+1} &\cdots & 0 \\
\vdots & & & \ddots & & & & & \vdots \\
1 & 0 & 0 & \cdots & 0 & 0 & 0 &\cdots & a_n \\
\end{matrix}\right| 
=
(-1)^{k + 1}\left|
\begin{matrix}
1 & 1 & \cdots & 1 & 1 & 1 &\cdots & 1 \\
a_1 & 0 & \cdots & 0 & 0 & 0&\cdots & 0 \\
0 & a_2 & \cdots & 0 & 0 & 0&\cdots & 0 \\
\vdots & & \ddots & & & & & \vdots \\
0 & 0 & \cdots & a_{k-1} & 0 & 0 &\cdots & 0 \\
0 & 0 & \cdots & 0 & 0 & a_{k+1} &\cdots & 0 \\
\vdots & & \ddots & & & & & \vdots \\
0 & 0 & \cdots & 0 & 0 & 0 &\cdots & a_n \\
\end{matrix}\right| 
$$
Row expand the matrix on the right (starting the bottom row), and you should get the determinant being $(-1)^{k+1}(-1)^ca_1 \cdots a_{k-1}a_{k+1} \cdots a_n$ for some integer $c$.
</s>