DMOPC '19 Contest 1 P6 - Bob and Binary Strings

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 1.4s
Memory limit: 512M

Author:
Problem types

Bob is playing with binary strings. He defines two strings S and T to be similar if at least one of the following conditions holds:

  1. S=T
  2. The lengths of both S and T must be divisible by 2. Let S1 denote the first half of S, and S2 denote the second half. Similarly, define T1 and T2 as the first and second halves of T. Then S and T are similar if either:
    • S1 is similar to T1 and S2 is similar to T2 or
    • S1 is similar to T2 and S2 is similar to T1

If both conditions do not hold then S and T are not similar.

Bob begins to wonder about N particular lengths of binary strings. These lengths are a1,a2,,aN.

For each ai, Bob generates all 2ai possible binary strings of length ai. He wonders how many ordered pairs of binary strings from his set are similar. Since these numbers may be massive, print the answers modulo 109+7.

Constraints

In all subtasks,
1N50
1ai1018

Subtask 1 [5%]

1ai5

Subtask 2 [10%]

All the ai are odd integers.

Subtask 3 [15%]

N=1
1ai26

Subtask 4 [10%]

N=1
1ai52

Subtask 5 [30%]

1ai1024

Subtask 6 [30%]

1ai1018

Input Specification

The first line contains a single integer, N.
N lines follow, the i-th of which containing a single integer, ai.

Output Specification

Output N lines, the i-th of which containing the answer modulo 109+7 for binary strings of length ai.

Sample Input 1

Copy
1
2

Sample Output 1

Copy
6

Sample Input 2

Copy
2
3
4

Sample Output 2

Copy
8
54

Explanation for Sample Output 2

There are a total of 8 ordered pairs of similar strings for binary strings of length 3, and there are a total of 54 ordered pairs of similar strings for binary strings of length 4.


Comments

There are no comments at the moment.