-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha63_q1a_101.cpp
More file actions
55 lines (47 loc) · 1.27 KB
/
Copy patha63_q1a_101.cpp
File metadata and controls
55 lines (47 loc) · 1.27 KB
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
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e8 + 7;
vector <vector <int>> multiply(vector <vector <int>> a, vector <vector <int>> b) {
vector <vector <int>> c(4, vector <int> (4));
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j]) % MOD;
}
}
}
return c;
}
vector <vector <int>> power(vector <vector <int>> &a, long long n) {
if (n == 1) return a;
vector <vector <int>> c = power(a, n / 2);
c = multiply(c, c);
if (n % 2 == 1) c = multiply(c, a);
return c;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
long long n;
cin >> n;
if (n == 1) cout << 1;
else if (n == 2) cout << 4;
else {
vector <vector <int>> dp(4, vector <int> (4));
dp[0][0] = 1;
dp[2][0] = 1;
dp[0][1] = 1;
dp[1][2] = 1;
dp[3][2] = 1;
dp[1][3] = 1;
dp[3][3] = 1;
vector <vector <int>> res = power(dp, n - 2);
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
ans = (ans + res[i][j]) % MOD;
}
}
cout << ans;
}
return 0;
}