typedef long long ll;
const int mod = 1000007; //结果假设取模1000007
int n,k; //n阶方阵(假设n<=10,N可以随之调整),幂次为k
struct Matrix {
static const int N = 15;
ll a[N][N];
Matrix(ll e = 0) {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
a[i][j] = e * (i == j);
}
Matrix mul(Matrix A, Matrix B) {
Matrix ans(0);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
for (int k = 1; k <= n; ++k)
ans.a[i][j] = (ans.a[i][j] + A.a[i][k] * B.a[k][j])%mod;
return ans;
}
Matrix ksm(Matrix A, int k) {
Matrix ans(1);
while (k) {
if (k & 1) ans = mul(ans, A);
A = mul(A, A);
k >>= 1;
}
return ans;
}
};
04-15