-
Notifications
You must be signed in to change notification settings - Fork 12
/
MAIN74-h.cpp
65 lines (58 loc) · 1.31 KB
/
MAIN74-h.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
#include<iostream>
using namespace std;
#define mod 1000000007
int size=2;
void multiply(long long int a[][3],long long int b[][3]){
int i,j,k;
long long int ans[3][3]={};
for(i=0;i<size;i++){
for(j=0;j<size;j++){
for(k=0;k<size;k++){
ans[i][j]=(ans[i][j] + a[i][k]*b[k][j])%mod;
ans[i][j]=ans[i][j]%mod;
}
}
}
for(i=0;i<size;i++){
for(j=0;j<size;j++){
a[i][j]=ans[i][j];
}
}
}
void power(long long int second[][3],long long int n){
long long int current[3][3]={},i,j;
for(i=0;i<size;i++){
for(j=0;j<size;j++)
current[i][j]=second[i][j];
}
if(n<=1){
return;
}
if(n&1){
power(second,n-1);
multiply(second ,current);
}
else{
power(second,n/2);
multiply(second,second);
}
}
int main(){
int t;
cin>>t;
while(t--){
long long int n;
cin>>n;
if(n==0)
{cout<<"0\n";continue;}
if(n==1)
{cout<<"2\n";continue;}
else{
long long int myArray[3][3];
myArray[0][0]=1;myArray[0][1]=1;myArray[1][0]=1;myArray[1][1]=0;
power(myArray,n+2);
cout<<myArray[0][0]%mod<<"\n";
}
}
return 0;
}