<s>[INST] How to calculate the determinant? I need help with this determinant ($n \times n)$: 
$D_n = \begin{vmatrix}
a & x & x & \dots & x & x \\ 
y & a & x & \dots & x & x \\
y & y & a & \dots & x & x \\
\vdots \\
y & y & y & \dots & a & x \\
y & y & y & \dots & y & a \\
\end{vmatrix}$
I tried to simplify it and derive a reсcurrent formula using Laplace expansion, but it was unsuccessful. Also I had an idea to express the determinant as a sum of determinants.
The answer is: $\displaystyle D_n = \frac{x(a-y)^n - y(a-x)^n}{x-y}$.
 [/INST] Subtract the 2nd column from the first, the 3rd from the second, etc.
Here is what you get in the $4\times4$ case:
$$D_4 = \begin{vmatrix}
a-x & 0 & 0 & x \\ 
y-a & a-x & 0 & x \\
0 & y-a & a-x & x \\
0 & 0 & y-a & a
\end{vmatrix}$$
Laplace expansion on the first column will yield:
$$D_4=(a-x)D_3-(y-a) \begin{vmatrix}
0 & 0 & x \\ 
y-a & a-x & x \\
0 & y-a & a
\end{vmatrix}$$
Then again Laplace expansion, on the first row:
$$D_4=(a-x)D_3-(y-a)x \begin{vmatrix}
y-a & a-x \\
0 & y-a \end{vmatrix}=(a-x)D_3-x(y-a)^3$$

General case: $D_n=(a-x)D_{n-1}-(-1)^nx(y-a)^{n-1}=(a-x)D_{n-1}+x(a-y)^{n-1}$, with $D_1=a$.
Then
$$\begin{align}
D_n & = &(a-x)^2D_{n-2}+(a-x)x(a-y)^{n-2}+x(a-y)^{n-1}\\
& = &(a-x)^3D_{n-3}+(a-x)^2x(a-y)^{n-3}+(a-x)x(a-y)^{n-2}+x(a-y)^{n-1}\\
& \vdots & \\
& = &(a-x)^{n-1}D_1+(a-x)^{n-2}x(a-y)+\dots+x(a-y)^{n-1}\\
\end{align}$$
Or
$$D_n=a(a-x)^{n-1}+x\sum_{k=0}^{n-2}(a-x)^{k}(a-y)^{n-1-k}$$
(if you don't like the dots, you can prove the previous formula by induction on $n$)
$$D_n=a(a-x)^{n-1}+x\left(\sum_{k=0}^{n-1}(a-x)^{k}(a-y)^{n-1-k}-(a-x)^{n-1}\right)$$
And, if $u\neq v$,
$$\sum_{k=0}^{n-1}u^{k}v^{n-1-k}=\frac{u^n-v^n}{u-v}$$
Hence, if $x\neq y$,
$$\begin{align}
D_n&=a(a-x)^{n-1}-x(a-x)^{n-1}+x\frac{(a-x)^n-(a-y)^n}{(a-x)-(a-y)}\\
&=(a-x)^{n}-x\frac{(a-x)^n-(a-y)^n}{x-y}\\
&=\frac{(x-y)(a-x)^{n}-x(a-x)^n+x(a-y)^n}{x-y}\\
&=\frac{x(a-y)^n-y(a-x)^{n}}{x-y}
\end{align}
$$
And if $x=y$, you take again the formula
$$\begin{align}
D_n&=a(a-x)^{n-1}+x\sum_{k=0}^{n-2}(a-x)^{k}(a-y)^{n-1-k}\\
&=a(a-x)^{n-1}+x(n-1)(a-x)^{n-1}\\
&=(a+(n-1)x)(a-x)^{n-1}
\end{align}$$
</s>