-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4071.cpp
More file actions
executable file
·43 lines (37 loc) · 929 Bytes
/
Copy path4071.cpp
File metadata and controls
executable file
·43 lines (37 loc) · 929 Bytes
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
/**
* 矩阵快速幂求斐波那契
**/
#include <iostream>
#define ll long long
using namespace std;
const ll mo = 1e9 + 7;
struct mat {
ll a11, a12, a21, a22;
mat():a11(0), a12(1), a21(1), a22(1) {}
mat operator*(const mat &other) const {
mat tmp;
tmp.a11 = (a11 * other.a11 % mo + a12 * other.a21 % mo) % mo;
tmp.a12 = (a11 * other.a12 % mo + a12 * other.a22 % mo) % mo;
tmp.a21 = (a21 * other.a11 % mo + a22 * other.a21 % mo) % mo;
tmp.a22 = (a21 * other.a12 % mo + a22 * other.a22 % mo) % mo;
return tmp;
}
};
mat binary_pow(ll n) {
mat tmp, cache;
tmp.a11 = 1; tmp.a12 = 0; tmp.a21 = 0; tmp.a22 = 1;
while(n > 0) {
if(n & 1) {
tmp = tmp * cache;
}
cache = cache * cache;
n >>= 1;
}
return tmp;
}
ll n;
int main() {
cin >> n;
mat a = binary_pow(n);
printf("%lld\n", a.a22);
}