Suppose your matrix is 3x3. Then given it has 3 distinct eigenvalues, $A$ can be diagonalised with its eigenvectors as its basis $B=\begin{pmatrix}v_1 & v_2 & v_3\end{pmatrix}$. That is:
$A=B^TD(\lambda_1,\lambda_2,0)B$, where $D$ is your diagonal matrix. Now you want a matrix $A'$ that has the eigenvalues as shown. Notice that for a diagonal matrix, the eigenvalues are indeed the diagonal elements only. Also since $A'$ and $A$ have the same eigenvectors, $B$ is the same. Therefore observe:
\begin{align}