The Travelling Ant
Practice
5 (3 votes)
Counting and arrangements
Dynamic programming
Algorithms
Matrix exponentiation
Medium
Problem
5% Success 2586 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There is an Ant that lives in Baskerville and loves to travel. As Baskerville is a small place, it consists of only 5 cities placed one next to each other.

There is a train between each successive cities ie between City 1 - City 2, City 2 - City 3, ... City 5 - City 1. Note that our Ant loves to travel and gets happy after making exactly N train trips and returning back to home.
Ant lives in the city 1 from where she begins her journey. She asks you to find the number of ways she can make N train trips and come back to home.

Since the number of ways can be huge, print that number modulo 10^9 + 7.

Input
First line contains T, the number of test cases.
Then T lines follow.
Each line contains a single integer n, representing the number of train trips the ant needs to make.

Output
For each test case, print a single line containing the answer to the problem.

Constraints
1 <= T <= 1000
0 <= n <= 10^18

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:20
222 votes
Tags:
AlgorithmsApprovedBinary SearchEasyMathOpenSorting
Points:20
368 votes
Tags:
Ad-HocApprovedEasyImplementationReadySorting
Points:30
2 votes
Tags:
DP