Prove or disprove that $A^n=B^n$ implies $A=B$ Given two square matrices $A,B$ such that $A^n=B^n$ for some $n&gt;2$. Is it necessarily true that $A=B$?

It is obvious that if $A^n=B^n=0$ then $A\neq B$ is not necessarily true. What if $A,B\in GL(n,\mathbb{R})$?

Scratching my head trying to come up with counter-examples.
\begin{eqnarray*}
\begin{pmatrix} 1 &amp; 0 \\ 0 &amp; -1 \end{pmatrix}^2 =\begin{pmatrix} -1 &amp; 0 \\ 0 &amp; 1 \end{pmatrix}^2.
\end{eqnarray*}
What is $\begin{bmatrix} 0 &amp; 1 \\ 1 &amp; 0 \end{bmatrix}^2$ ?