Let $A,B\in M_n(\mathbb{R})$ be symmetric matrices such that $A^5=B^5$. Prove that $A=B$.
My attempt:
If $A$ and $B$ are symmetric matrices we can use the espectral theorem to write $A=\lambda_1 E_1+\lambda_2 E_2+...+\lambda_k E_k$ where $\lambda_i$ are the eingenvalues, $E_i$ are projections and this writing is unique and $B=\alpha_1 E_1+\alpha_2 E_2+...+\alpha_s E_s$, but as $A^5=B^5$ then, we have that $\lambda^5_1 E_1+\lambda^5_2 E_2+...+\lambda^5_k E_k=\alpha^5_1 E_1+\alpha^5_2 E_2+...+\alpha^5_s E_s$.
As the writing is unique, we have that $k=s$ and $\lambda^5_i=\alpha^5_i$ then $\lambda_i=\alpha_i$ and $A=B$.
Is this correct?