I have been given the value of $a+b$ , $ab$ and $n$. I've to calculate the value of $a^n+b^n$. How can I do it?
I would like to find out a general solution. Because the value of $n$ , $a+b$ and $ab$ might be as large as $10^9$. Then I have to calculate the last 10 digits only.
NB: I've found this problem in the category of Matrix Exponentiation.
Call $s=a+b$, $p=ab$, and $s_n=a^n+b^n$ for every $n\geqslant0$, then $ss_n=s_{n+1}+ps_{n-1}$ for every $n\geqslant1$ hence one can compute recursively $(s_n)_{n\geqslant0}$ using $$ s_0=2\qquad s_1=s\qquad s_{n+1}=ss_n-ps_{n-1}\ (n\geqslant1). $$ Alternatively, the vectors $v_n=(s_n,s_{n-1})$ are such that $v_{n+1}=v_nM$, where $M=\begin{pmatrix}s & 1 \\ -p & 0\end{pmatrix}$, hence $v_n=(s,2)M^{n-1}$ for every $n\geqslant1$, that is, if $M^k=\begin{pmatrix}x_k & y_k \\ z_k & t_k\end{pmatrix}$, then $s_n=sx_{n-1}+2z_{n-1}$ or $s_n=sy_n+2t_n$.