-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMAIN74.cpp
31 lines (29 loc) · 833 Bytes
/
MAIN74.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
// used fast_doubling method to compute the fibonacci numbers
// f(2n) = f(n)(2f(n+1) - f(n)), f(2n+1) = f(n)^2 + f(n+1)^2
pair<ll, ll> get_nums(ll n){
if(!n) return {0, 1};
pair<ll, ll> p = get_nums(n >> 1);
ll term1 = (p.first * ((p.second << 1) % mod - p.first + mod) % mod ) % mod;
ll term2 = ((p.first * p.first) % mod + (p.second * p.second) % mod) % mod;
if(n&1) return {term2, term1 + term2};
return {term1, term2};
}
int main(){
ll n;
int t;
cin >> t;
while(t--){
cin >> n;
if(n==0) cout << 0;
else if(n==1) cout << 2;
else {
pair<ll, ll> p = get_nums(n+1);
cout << (p.first + p.second) % mod;
}
cout << endl;
}
}