struct Matrix
{
LL m[ms][ms];
} ans, base;
Matrix multi(Matrix a, Matrix b)
{
Matrix tmp;
for(int i = 0; i < ms; i++)
for(int j = 0; j < ms; j++)
{
tmp.m[i][j] = 0;
for(int k = 0; k < ms; k++)
tmp.m[i][j] = (tmp.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;
}
return tmp;
}
LL Pow(LL x)
{
base.m[0][0] = 1, base.m[0][1] = 1;
base.m[1][0] = 1, base.m[1][1] = 0;
ans.m[0][0] = 1, ans.m[0][1] = 0;
ans.m[1][0] = 0, ans.m[1][1] = 1;
while(x)
{
if(x & 1)
ans = multi(ans, base);
base = multi(base, base);
x >>= 1;
}
}
【矩阵快速幂】
最新推荐文章于 2021-10-22 12:29:51 发布