P14709 [ICPC 2023 Tehran R] Jackson House
Description
Jackson, after witnessing the advancements in the world of technology, decided to sell his small cozy house and enroll in the programming-and-algorithm micromaster. He came across an interesting algorithm that he needed to analyze and solve the problem related to it, in order to pass the exam at this stage of the course. The pseudocode of this algorithm is as follows:
$$
\begin{array}{l}
\textbf{input:} \text{ a permutation } \pi = \langle \pi_1, \pi_2, \ldots, \pi_n \rangle \text{ of numbers } \{1, 2, \ldots, n\} \\
\textbf{while } \pi \text{ is changing during this iteration:} \\
\quad \textbf{for } i := n \textbf{ downto } 2: \\
\quad\quad \textbf{if } \pi_i < \pi_{\lfloor i/2 \rfloor}: \\
\quad\quad\quad \text{swap}(\pi_i, \pi_{\lfloor i/2 \rfloor})
\end{array}
$$
He wants to know for how many permutations $\pi$ of length $n$ from the possible $n!$ ones, the final permutation will be sorted after running this algorithm.
Input Format
The first line contains an integer $t$ ($1 \leq t \leq 100$), the number of test cases.
Each of the next $t$ lines contains an integer $n_i$ ($2 \leq n_i \leq 10^9$), representing the length of the permutation for the $i^{th}$ test case.
Output Format
Output $t$ lines. On the $i^{th}$ line, print the number of permutations of length $n_i$ which will be sorted after running the provided algorithm on it. Since the output could be very large, output the result modulo $10^9 + 7$.