SAFECRAC - Crack the Safe


Johnny (not little anymore) is a super agent .He is been following up on leads against the world’s worst terrorists. He got a intel that a terrorist is staying at an expensive hotel. Only thing that stops LJ is the secure door in the room entrance.

The secure door had a lock which resembled this,

1 2 3
4 5 6
7 8 9
0 Enter

The enter key cannot be a part of the pass-code

When Johnny did some spy work on it, he found out that every pair of neighbouring digits in the pass code is adjacent on the keypad. Adjacent means that the digits share a common edge.

Now he wants to know how many different possibilities are there for the pass code so that he can bring a computer accordingly to hack the lock.

Input

Input begins with single integer ‘T’ denoting number of test cases and T lines follow. Each line contains the number ‘N’ denoting the length of the pass code.

Output

For each test case T, output the number of different possibilities in a new line. Since the answer can be huge output the number mod 1000000007.

Constraints:

1 <= T <= 1,000

1 <= N <= 100,000

Sample

Input: 
2
3
25

Output:
74
478325846

hide comments
ROHIT RAJ: 2015-09-29 12:04:44

precompute :D

Bumbler: 2015-02-03 18:02:50

How can I solve this problem in logn ? I did precomputation in O(n) dp. And then O(1) per query. This worked because n is small. Please mail me the logn solution / explanation @ piyush1.cse16@mnnit.ac.in

Last edit: 2015-02-03 18:04:20
RAJDEEP GUPTA: 2013-02-28 07:09:31

@Aditya Pande : My O(logn) algorithm whith no I/O optimization passed.

Aditya Pande: 2013-02-26 13:12:57

TLE with O(log n)? let me think of something better...

Last edit: 2013-02-26 13:14:19
Francky: 2013-02-22 19:02:02

Is everybody ready for the challenge edition ? It's here :

http://www.spoj.com/problems/SPPC

Have fun.

Last edit: 2013-03-20 20:19:02
(Tjandra Satria Gunawan)(曾毅昆): 2013-02-21 12:29:52

Ok Francky, Good luck...

Francky: 2013-02-21 12:08:40

So OK for the hardest variation, and no bignum for tjandra (haha). It wasn't my intention anyway, ...
I'm already trying some experiments on the 'best' lock... It will not be ready today...

(Tjandra Satria Gunawan)(曾毅昆): 2013-02-21 11:58:25

@Francky: Yes, you can make the hard problem if you like, but it's not guaranteed that I can solve it, My fatal weakness is to deal with big integer (>2^64 even on intermediate operation).. And yes I want "harder" problem, but not too hard.. I will happy if I can gain more points, haha...

Last edit: 2013-03-01 15:23:11
Francky: 2013-02-21 11:41:39

Edit : 0.04s with O(N), slow I/O, no opti... haha.

@tjandra : I can set a new problem if you want with a much bigger lock (A to Z for example) and harder constraints. How hard do you want it ? Maximal difficulty but python3 feasible ?

Is OK for everybody ?

Last edit: 2013-02-21 15:23:13
(Tjandra Satria Gunawan)(曾毅昆): 2013-02-21 11:11:45

what is this? too easy... My program can compute the answer in O(log(N))... and limit for N is only 10^5?? Come on, Please make this problem harder by increasing the limit for N to 2^64.. My last submited C code, will not overflow until 2^64 ;-) you can use my code to generate new test data...

Last edit: 2013-02-21 11:13:30

Added by:J.A.R.V.I.S.
Date:2013-02-14
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Own