-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeForces - B_String_Mood.cpp
58 lines (46 loc) · 1.04 KB
/
CodeForces - B_String_Mood.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
#include <bits/stdc++.h>
#define MX vector<vector<T>>
#define MOD 1000000007
using namespace std;
template<typename T>
MX mult(MX a, MX b) {
MX result = {{0, 0}, {0, 0}};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
result[i][j] = (result[i][j] + (a[i][k] * b[k][j]) % MOD) % MOD;
}
}
}
return result;
}
template<typename T>
MX binary(MX a, long long n) {
MX result = {{1, 0}, {0, 1}};
while (n > 0) {
if (n % 2 == 1) {
result = mult(result, a);
n--;
}
a = mult(a, a);
n /= 2;
}
return result;
}
template<typename T>
void print(MX a) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
int main() {
long long n;
cin >> n;
vector<vector<long long>> m = {{19, 7}, {6, 20}};
auto result = binary(m, n);
cout << result[0][0] << endl;
return 0;
}