-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOJ_11442.cpp
48 lines (43 loc) · 1.02 KB
/
BOJ_11442.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
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000000
const ll INF = 10e12 + 10;
using namespace std;
typedef vector<vector<long long> > matrix;
const long long mod = 1000000007LL;
matrix operator *(const matrix &a, const matrix &b) {
int n = a.size();
matrix c(n, vector<long long>(n));
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];
}
c[i][j] %= mod;
}
}
return c;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
long long n;
cin >> n;
if (n % 2)n++;
if (n <= 1) {
cout << n << '\n';
return 0;
}
matrix ans = {{1, 0}, {0, 1}};
matrix a = {{1, 1}, {1, 0}};
while (n > 0) {
if (n % 2 == 1) {
ans = ans * a;
}
a = a * a;
n /= 2;
}
cout << ans[0][1] << '\n';
}