We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f9517b4 commit ec518b1Copy full SHA for ec518b1
1 file changed
Matrix
@@ -0,0 +1,31 @@
1
+struct Matrix {
2
+ vector <vector <int>> m;
3
+ int r, c;
4
+
5
+ Matrix(int rr = 0, int cc = 0) : r(rr), c(cc) {
6
+ m.resize(r, vector <int>(c));
7
+ }
8
9
+ Matrix operator * (const Matrix& a) {
10
+ Matrix ret(r, c);
11
+ for (int i = 0; i < r; i++) {
12
+ for (int j = 0; j < c; j++) {
13
+ int& ref = ret.m[i][j];
14
+ for (int k = 0; k < c; k++)
15
+ ref = (1ll * ref + 1ll * m[i][k] * a.m[k][j]) % mod;
16
17
18
+ return ret;
19
20
21
+ Matrix power(long long b) {
22
23
+ for (int i = 0; i < r; i++) ret.m[i][i] = 1;
24
+ Matrix a = *this;
25
+ while (b) {
26
+ if (b & 1) ret = ret * a;
27
+ b >>= 1; a = a * a;
28
29
30
31
+};
0 commit comments