Calculate $A^5 - 27A^3 + 65A^2$, where $A$ is the matrix defined below. If $A=\begin{bmatrix} 0 & 0 & 1 \\
3 & 1 & 0 \\ 
-2&1&4\end{bmatrix}$, find $A^5 - 27A^3 + 65A^2$
$$A=\begin{bmatrix} 0 & 0 & 1 \\
3 & 1 & 0 \\ 
-2&1&4\end{bmatrix}$$
Let $\lambda$ be its eigenvalue, then 
$$(A-\lambda I) = \begin{bmatrix} 0-\lambda & 0 & 1 \\
3 & 1-\lambda & 0 \\ 
-2&1&4-\lambda\end{bmatrix}$$
$$|A-\lambda I| = -(\lambda)^3 + 5(\lambda)^2 - 6(\lambda) +5$$
Using Cayley-Hamilton theorem
$$A^3-5^2+6A-5=0$$
How do I use this find $A^5 - 27A^3 + 65A^2$?

Doing long division:
$$A^5-27A^3+65A^2=(A^2+5A-8)(\underbrace{A^3-5A^2+6A-5}_{=0})+73A-40.$$
Hence it is:
$$A^5-27A^3+65A^2=73A-40I=\begin{pmatrix}-40&0&73\\ 219&33&0\\-146&73&252\end{pmatrix}.$$
