Roy and Ring
Practice
0 (0 votes)
Medium
Ad Hoc
Linear algebra
Matrix exponentiation
Algorithms
Mathematics
Open
Approved
Problem
8% Success 912 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Roy bought a Ring for Alfi, his girlfriend :p. But Alfi will only accept the Ring if Roy played a game with her and answered her queries correctly during the game.

Alfi places a ring at origin of a Cartesian Plane. Both Alfi and Roy move the ring alternatively. Alfi takes odd steps and Roy takes even steps.

Direction of Movement: Alfi always moves either left or right alternatively, i.e. if she moved left in her last step, she will move right in her current step. Initially she moves right. Roy always moves up or down alternatively, i.e if he moved up in his last step, he will move down in his current step. Initially he moves up.

Displacement of Ring: Initially both of them displace the ring by 1 unit. During Alfi's turn(other than her first step), she sums up her last displacement and Roy's last displacement, and moves the Ring by the value thus obtained. Similary, during Roy's turn(other than his first step), he sums up his last displacement and Alfi's last displacement, and moves the Ring by the value thus obtained.

Sample example of movements:

enter image description here

Now that the direction and displacement of Ring's movements are clear. Its time to answer Alfi's weird queries.

Given the step number N, what is the perpendicular distance of Ring from Y-axis after that step. Now Alfi is such an impatient girl, she wants him to answer as quickly as possible, otherwise she won't accept the Ring.

Input:

First line of input will contain integer Q, number of queries. Next Q lines each will contain integer N, step number of the game.

Output:

Print the result of each query in a new line. Since the result can be very large, print it modulo 1000000007

Constraints:

1<=Q<=10000

1<=N<=1000000000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
27 votes
Tags:
Graph TheoryLinear AlgebraApprovedMediumAlgorithmsMathematicsOpenMatrix Exponentiation
Points:30
Tags:
Modular exponentiationMediumMatrix ExponentiationMathematics
Points:30
Tags:
Medium