-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuce.cpp
68 lines (61 loc) · 1.07 KB
/
suce.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
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<long long> vi;
#define INF 1000000000
#define endl '\n'
const ll M = 1e9+7;
vector<vi> multimat(vector<vi> &a, vector<vi> &b){
vector<vi>ans = {
{0, 0},
{0, 0}
};
int n = a.size();
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
for(int k=0; k<n; k++){
ans[i][j] = ((a[i][k]%M*b[k][j]%M)+ans[i][j])%M;
}
}
}
return ans;
}
vector<vi>powermat(vector<vi> &a, ll b){
vector<vi>ans = {
{1, 0},
{0, 1}
};
while(b){
if(b&1){
ans = multimat(ans,a);
}
a = multimat(a, a);
b>>=1;
}
return ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
ll n;
cin>>n;
if(n == 0){
cout<<0<<endl;
return 0;
}
if( n == 1){
cout<<1<<endl;
return 0;
}
vector<vi>a = {
{1, 1},
{1, 0}
};
vector<vi> ans = powermat(a, n-2);
cout<<(ans[0][0]+ans[1][0])%M<<endl;
return 0;
}
//puentes
//puntos de articulacion
// componentes fuertemente conexos