$$X= \begin{pmatrix} 2-n & 1 & 1 & 1 & \ldots & 1 & 1 \\ 1 & 2-n & 1 & 1 & \ldots & 1 & 1 \\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ 1 & 1 & 1 & 1 & \ldots & 2-n & 1 \\ 1 & 1 & 1 & 1 & \ldots & 1 & 2-n\end{pmatrix}_{n\times n} $$
Which means that the matrix with the size of $n\times n$ have $n-2$ along the diagonal and $1$ everywhere else. Help please, I am stuck with this problem.
HINT: Let $B$ be the $n\times n$ matrix of ones. Then $XB=B$, so
$$X(B-I)=XB-X=B-X=(n-1)I\;,$$
where $I$ is the $n\times n$ identity matrix.
By the way, manually calculating the inverses for $n=2$ and $n=3$ was enough to suggest what the answer ought to be, and discovering the argument suggested above was then quite easy.