Matrix Exponentiation
Medium Accuracy: 20.15% Submissions: 813 Points: 4

Given an equation of the form F(n) = F(n-2) + F(n-3) where F(0) = 1, F(1) = 0, F(2) = 1 , the task is to find the nth term of this sequence.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N.

Output:
For each test case in a new line print the nth term of the sequence mod 10^9+7.

Constraints:
1<=T<=100
1<=N<=10^18+5

Example:
Input:

2
3
6

Output:
1
2

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.