Question: For an array $(n\_1,...,n\_k)$ of non-negative integers and non-zero reals $a\_1,...,a\_k$, define a block matrix $M$ of size $n=n\_1+\cdots+n\_k$ as follows:
The main diagonal has blocks of sizes $n\_i$ and shapes $$M\_i=J\_{n\_i}+a\_i I\_{n\_i}=\begin{pmatrix} 
a\_i+1&1&\cdots&1\\
1&a\_i+1&\ddots&\vdots\\
\vdots&\ddots&\ddots&1\\
1&1&1&a\_i+1\\
\end {pmatrix}$$ and all the other entries are $-1$.  

Experimentally I have found $$\det(M)= \prod\_{i=1}^k a\_i^{n\_i}\sum\_{j=0}^k(2-j)2^{j-1}e\_j =\prod a\_i^{n\_i}(1+e\_1-4e\_3-16e\_4-48e\_5-\cdots),$$
where $e\_j$ is the $j^{th}$ elementary symmetric function of $\dfrac{n\_1}{a\_1},\dots,\dfrac{n\_k}{a\_k}$.  

It should be a bit technical but not too hard to prove that by induction, but **is there a more elegant way?**

Answer: 
We have $M = D - e e^T$, where $D$ is a block diagonal matrix with main diagonals equal to $D\_i = \mathrm{diag}(a\_i) + 2 J\_i$, and $e$ is all ones vector with suitable dimention. By [Matrix determinant lemma](https://en.wikipedia.org/wiki/Matrix_determinant_lemma) we have
$$\det(M) = (1- e^TD^{-1}e) \det(D)$$
and
$$\det(D) = \prod\_i\det(D\_i) = \prod\_i (1+ 2\frac{n\_i}{a\_i})a\_i^{n\_i}$$
Also, by [Sherman–Morrison formula](https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula), we have

$$D\_i^{-1} = \mathrm{diag}(a\_i^{-1}) - \frac{2\mathrm{diag}(a\_i^{-1})J\_i\mathrm{diag}(a\_i^{-1})}{1+2 n\_i/a\_i}$$. So, 

$$1-e^TD^{-1}e = 1- \sum\_i\frac{n\_i}{a\_i} + \sum\_i \frac{2(n\_i/a\_i)^2}{1+2 n\_i/a\_i} = \sum\_i \frac{1+ n\_i/a\_i}{1+2n\_i/a\_i}$$
Therefore 
$$\det(M) = (\sum\_i \frac{1+ n\_i/a\_i}{1+2n\_i/a\_i}) \prod\_i (1+ 2\frac{n\_i}{a\_i})a\_i^{n\_i} \\= \prod\_{i=1}^k a\_i^{n\_i} \sum\_{j=0}^k (2-j)2^{j-1}e\_j$$
Alternatively, one may just inspect the eigenvalues (whose product is the determinant).

Clearly, all the vectors whose support lies in the $i$th block, and whose coordinates sum up to $0$, are eigenvectors with eigenvalue $a\_i$; hence $a\_i$ is the eigenvalue with multiplicity (at least) $n\_i-1$.

An invariant complement to the sum of already found subspaces is the set $V$ of all block-constant vectors; so we need to check the determinant of the restriction onto $V$. A natural base in $V$ consists of the vectors havig ones in the $i$th block, and zeroes elsewhere. The matrix in this base is 
$$
 A=\left(
 \begin{array}{ccccccccc}
 n\_1+a\_1& -n\_2& -n\_2& \cdots& -n\_k\\
 -n\_1& n\_2+a\_2& -n\_3& \cdots& -n\_k\\
 -n\_1& -n\_2& n\_3+a\_3& \cdots& -n\_k\\
 \vdots& \vdots& \vdots& \ddots& \vdots\\
 -n\_1& -n\_2& -n\_3& \cdots& n\_k+a\_k
 \end{array}
 \right),
$$
whose determinant is $n\_1n\_2\dots n\_k$ times the determinant of
$$
 B=\left(
 \begin{array}{ccccccccc}
 1+a\_1/n\_1& -1& -1& \cdots& -1\\
 -1& 1+a\_2/n\_2& -1& \cdots& -1\\
 -1& -1& 1+a\_3/n\_3& \cdots& -1\\
 \vdots& \vdots& \vdots& \ddots& \vdots\\
 -1& -1& -1& \cdots& 1+a\_k/n\_k
 \end{array}
 \right).
$$
Its determinant may be computed either directly, or via the same Matrix determinant lemma, yielding
$$
 \det B=\prod\_{i=1}^k\left(2+\frac{a\_i}{n\_i}\right)
 -\sum\_{i=1}^k
 \prod\_{\textstyle{1\leq j\leq k\atop j\neq i}}
 \left(2+\frac{a\_j}{n\_j}\right).
$$
After substituting into
$$
 \det M=\det B\cdot \prod\_{i=1}^k n\_ia\_i^{n\_i-1}
$$
and expanding the brackets, we get the desired result. (Although, I would admit, the form it has been obtained in does not look much worse for me.)