DMOPC '19 Contest 1 P6 - Bob and Binary Strings

View as PDF

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

Author:
Problem types

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

1. = 2. The lengths of both and must be divisible by . Let denote the first half of , and denote the second half. Similarly, define and as the first and second halves of . Then and are similar if either:
• is similar to and is similar to or
• is similar to and is similar to If both conditions do not hold then and are not similar.

Bob begins to wonder about particular lengths of binary strings. These lengths are .

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

Constraints   All the are odd integers.      Input Specification

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

Output Specification

Output lines, the -th of which containing the answer modulo for binary strings of length 1
2

6

2
3
4

8
54

Explanation for Sample Input 2

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