# 数列求值-------------------------------------------思维(矩阵快速幂)

Fn = [ f n f n + 1 ] \begin{bmatrix}fn & fn+1 \end{bmatrix}
Fn+1 = [ f n + 1 f n + 2 ] \begin{bmatrix}fn+1 & fn+2\end{bmatrix}

[ f n f n + 1 ] \begin{bmatrix}fn & fn+1\end{bmatrix} * [ 0 c 1 b ] \begin{bmatrix}0 & c\\ 1 & b\\\end{bmatrix} = [ f n + 1 f n + 2 ] \begin{bmatrix}fn+1 & fn+2 \end{bmatrix}

[ 0 1 ] \begin{bmatrix}0 & 1\end{bmatrix} * [ 0 c 1 b ] \begin{bmatrix}0 & c\\ 1 & b\\\end{bmatrix} n = [ f n + 1 f n + 2 ] \begin{bmatrix}fn+1 & fn+2 \end{bmatrix}


class Solution {
public:
long long  MOD=1000000007;
struct lxw
{
long long  res[2][2];
}node,base;
lxw multi(lxw a,lxw b)
{

lxw tmp;
memset(tmp.res,0,sizeof tmp.res);
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
tmp.res[i][j]=(tmp.res[i][j]+a.res[i][k]*b.res[k][j])%MOD;
return tmp;
}
long long nthElement(long long n, long long b, long long c) {
memset(node.res,0,sizeof node.res);
memset(base.res,0,sizeof base.res);
node.res[0][0]=0;node.res[0][1]=1;
base.res[0][1]=c;base.res[1][0]=1;base.res[1][1]=b;

while(n){
if(n&1) node=multi(node,base);
base=multi(base,base);
n>>=1;
}

return node.res[0][0]%MOD;
}
};

09-22
12-24 544

01-19 784
08-03 1081
12-31 1533
05-14 3277
08-10 266
10-03 1万+
02-19 671
10-10 3392