题目链接:https://www.luogu.org/problemnew/show/P1962
给你篇dalao的blog自己看吧,把矩阵快速幂的板子一改就OK
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
struct Matrix{
long long m[][];
}A,E,ans;
long long n,k, mod = ;
Matrix mul(Matrix A,Matrix B)
{
Matrix C;
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
{
C.m[i][j] = ;
for(int k = ; k <= ; k++)
C.m[i][j] = (C.m[i][j]+(A.m[i][k]*B.m[k][j]))%mod;
}
return C;
}
Matrix fast(Matrix A, long long k)
{
Matrix S = E;
while(k)
{
if(k&) S = mul(S,A);
A = mul(A,A);
k = k>>;
}
return S;
}
int main(){ scanf("%lld",&k); E.m[][] = ;
E.m[][] = ;
A.m[][] = ;
A.m[][] = ;
A.m[][] = ;
ans = fast(A,k); printf("%lld ",(ans.m[][])%mod);
return ;
}