<s>[INST] Given a matrix $A$ find $A^n$. $A=$$
    \begin{bmatrix}
    1 & 2\\ 
    0 & 1  
    \end{bmatrix} $
Find $A^n$. 
My input: 
$A^2= \begin{bmatrix}
    1 & 2\\ 
    0 & 1  
    \end{bmatrix} 
\begin{bmatrix}
    1 & 2\\ 
    0 & 1  
    \end{bmatrix}  = \begin{bmatrix}
    1 & 4\\ 
    0 & 1  
    \end{bmatrix} $
$A^3 = \begin{bmatrix}
    1 & 6\\ 
    0 & 1  
    \end{bmatrix} $
......
$A^n = \begin{bmatrix}
    1 & 2n\\ 
    0 & 1  
    \end{bmatrix} $
This was very basic approach. I want to know if there is any other way a smart trick or something to solve this problem ?  
 [/INST] The minimal polynomial of $A$ is $(x-1)^2$ so for any entire function $f$ we have
$$f(A) = f(1)P + f'(1)Q$$
for some $P, Q$ polynomials in $A$.
Plugging in $f \equiv 1$ and $f(x) = x$ we get $P = I$ and $Q = A-I$.
Therefore for $f(x) = x^n$ we have
$$A^n = 1^n\cdot I + n1^{n-1}\cdot (A-I) = I + n(A-I) = \begin{bmatrix} 1 & 2n \\ 0 & 1\end{bmatrix}$$
</s>