-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixd.cpp
More file actions
101 lines (70 loc) · 1.35 KB
/
Copy pathmatrixd.cpp
File metadata and controls
101 lines (70 loc) · 1.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
// matrix of 64 bit floating point integers
// useful for numerical problems
//////////////////////////////////////////////////////////////
const int MAXN = 20;
struct matrix{
int N = MAXN; // N <= MAXN
ld a[MAXN][MAXN];
matrix(){
memset(a, 0, sizeof(a));
}
matrix(int n){
N = n;
memset(a, 0, sizeof(a));
}
decltype(a[0]) operator[](int x){
return a[x];
}
static matrix I(int n){
matrix m(n);
for(int i = 0; i < n; i++) m[i][i] = 1.0;
return m;
}
matrix friend inverse(matrix &a){
matrix c;
return c;
}
matrix friend operator*(matrix &a, matrix &b){
matrix c;
for(int i=0; i<a.N; i++){
for(int j=0; j<a.N; j++){
for(int k = 0; k<a.N; k++){
c[i][j] += 1ll * a[i][k] * b[k][j] % mod;
if(c[i][j] >= mod) c[i][j] -= mod;
}
}
}
return c;
}
matrix friend operator^(matrix &a, ll b){
if(b < 0){
return inverse(a)^-b;
}
matrix ans = I(a.N);
while(b){
if(b%2!=0) ans = ans*a;
a = a*a;
b>>=1;
}
return ans;
}
};
//////////////////////////////////////////////////////////////
int main(){
matrix m(2);
m[0][0] = 0;
m[0][1] = 3;
m[1][0] = 1;
m[1][1] = 2;
ll n;
cin >> n;
m = m ^ n;
cout << (m[0][0])<< endl;
return 0;
}