-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend_assignment.cpp
58 lines (49 loc) · 1.12 KB
/
backend_assignment.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
#include <cstdio>
#include <iostream>
#define MOD 1000000007
using namespace std;
void multiply(long long int F[2][2], long long int M[2][2])
{
long long int x = ((F[0][0]*M[0][0])%MOD + (F[0][1]*M[1][0])%MOD)%MOD;
long long int y = ((F[0][0]*M[0][1])%MOD + (F[0][1]*M[1][1])%MOD)%MOD;
long long int z = ((F[1][0]*M[0][0])%MOD + (F[1][1]*M[1][0])%MOD)%MOD;
long long int w = ((F[1][0]*M[0][1])%MOD + (F[1][1]*M[1][1])%MOD)%MOD;
F[0][0] = x;
F[0][1] = y;
F[1][0] = z;
F[1][1] = w;
}
void power(long long int F[2][2], long long int n)
{
if( n == 0 || n == 1)
return;
long long int M[2][2] = {{1,1},{1,0}};
power(F, n/2);
multiply(F, F);
if (n%2 != 0)
multiply(F, M);
}
long long int function(long long int n)
{
long long int F[2][2] = {{1,1},{1,0}};
if (n == 0)
return 0;
if (n == 1)
return 2;
if (n == 2)
return 3;
power(F, n-2);
return (F[0][0]*3+F[0][1]*2)%MOD;
}
int main()
{
long long int T;
cin >> T;
while(T--)
{
long long int num;
cin >> num;
cout << function(num) << endl;
}
return 0;
}