#include<iostream> #include<cstdio> #include<cstring> usingnamespace std; using ll = longlong; constint maxn = 105; structMatrix{ int n, m; int v[maxn][maxn]; Matrix(int n, int m) : n(n), m(m) {}
voidinit(){ memset(v, 0, sizeof(v)); }
Matrix operator* (const Matrix B) const { Matrix ans(n, B.m); // for ans ans.init(); for (int i = 0; i < n; i++) { for (int j = 0; j < B.m; j++) { for (int k = 0; k < m; k++) { ans.v[i][j] = ans.v[i][j] + v[i][k] * B.v[k][j]; } } } return ans; }
voidprint(){ for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << v[i][j] << " "; } cout << endl; } } };
Matrix q_pow(Matrix& A, int b){ Matrix ret(A.n, A.m);
ret.init(); for (int i = 0; i < ret.n; i++) { // 初始化E ret.v[i][i] = 1; }
while (b) { if (b & 1) { ret = ret * A; } A = A * A; b >>= 1; } return ret; }
intfib(int n){ int dp[n]; dp[0] = 1, dp[1] = 1; for (int i = 2; i < n; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[n - 1]; }