本文参考自: 原文地址
//矩阵快速幂
typedef long long LL;
const LL MOD=1e9+7;
const int N=4;
struct node{
LL a[10][10];
};
node shu,ans,mp;
//shu是输入的矩阵,ans是所求答案
node matrix(node x,node y)
{
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
mp.a[i][j]=0;
for(int p=1;p<=N;p++){
mp.a[i][j]=(mp.a[i][j]+x.a[i][p]*y.a[p][j]+MOD)%MOD;
}
}
}
return mp;
}
void work(LL k)
{
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
ans.a[i][j]=0;
}
}
for(int i=1;i<=N;i++){
ans.a[i][i]=1;
}
node t=shu;
while(k){
if(k&1){
ans=matrix(ans,t);
}
k>>=1;
t=matrix(t,t);
}
}