-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmet.sublime-snippet
77 lines (68 loc) · 1.52 KB
/
met.sublime-snippet
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
<snippet>
<content><![CDATA[
struct matrix
{
long long int arr[2][2];
};
matrix matrixMult(matrix A, matrix B)
{
matrix C;
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
C.arr[i][j] = 0;
for(int k=0; k<2; k++)
{
C.arr[i][j] += A.arr[i][k]*B.arr[k][j];
C.arr[i][j] %= MOD;
}
}
}
return C;
}
matrix myPow(matrix A, long long int N)
{
if(N == 1)
return A;
matrix half = myPow(A, N/2);
matrix ans;
ans = matrixMult(half, half);
if(N&1)
ans = matrixMult(ans, A);
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t;
cin >> t;
matrix transitionMatrix;
transitionMatrix.arr[0][0] = 1;
transitionMatrix.arr[0][1] = 1;
transitionMatrix.arr[1][0] = 1;
transitionMatrix.arr[1][1] = 0;
while(t--)
{
long long int N;
cin >> N;
if(N == 1)
cout << "1" << endl;
else if(N == 2)
cout << "2" << endl;
else
{
matrix ans = myPow(transitionMatrix, N-2);
cout << (2*ans.arr[0][0] + ans.arr[0][1])%MOD << endl;
}
}
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>_met</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>