-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOJ_12850.cpp
60 lines (55 loc) · 1.33 KB
/
BOJ_12850.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
const ll INF = 10e12 + 10;
using namespace std;
typedef vector<vector<long long> > matrix;
matrix operator *(const matrix &a, const matrix &b) {
int n = a.size();
matrix c(n, vector<long long>(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
c[i][j] += (a[i][k] * b[k][j]) % MOD;
c[i][j] %= MOD;
}
}
}
return c;
}
matrix A = {
{0, 1, 0, 0, 0, 1, 0, 0},
{1, 0, 1, 0, 0, 0, 1, 0},
{0, 1, 0, 1, 0, 0, 1, 1},
{0, 0, 1, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1, 0},
{0, 1, 1, 0, 0, 1, 0, 1},
{0, 0, 1, 1, 1, 0, 1, 0}
};
matrix ans = {
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 1}
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int d;
cin >> d;
while (d > 0) {
if (d % 2) {
ans = ans * A;
}
A = A * A;
d /= 2;
}
cout << ans[4][4] << '\n';
}