#P10035. 「FAOI-R2」Paint

「FAOI-R2」Paint

Background

Xiao Y is a chubby kid. He loves going downstairs because it takes less effort, but he has obsessive-compulsive tendencies.

Because the painter HG does not have enough paint, each step is painted only halfway—either the left half or the right half—so that Xiao Y will not step on the paint when going downstairs. (Everyone: What kind of logic is this?)

Problem Description

The whole staircase has 3N3^N steps.

HG’s painting rule is: for the II-th step from top to bottom, if V3(I)V_3(I) is odd, then he paints the left half; otherwise, he paints the right half. For the definition of V3(I)V_3(I), see the Hint.

Because of his OCD, Xiao Y requires that he must not step on the paint.

Now he asks you for help: what is the minimum number of times he will step on the paint?

  • Each move can only go down one step.
  • If Xiao Y stands on the left side of the current step, then he must stand on the right side of the next step, and vice versa.
  • If the paint is on the left side of the current step, then only standing on the right side counts as not stepping on the paint, and vice versa.
  • The only thing Xiao Y can control is which side he stands on at step 11. That is, Xiao Y has only 22 possible ways to go downstairs.

Output the answer modulo 109+710^9+7.

Formal Statement

Given three binary strings A,B,CA,B,C, all of length 3N3^N. String indices start from 11.

Where:

  • A=101010101101A=\texttt{101010101\ldots101};
  • B=010101010010B=\texttt{010101010\ldots010};
  • C=001001000C=\texttt{001001000\ldots}; specifically, the II-th character is V3(I)mod2V_3(I) \bmod 2. For the definition of V3(I)V_3(I), see the Hint.

Let mc(X,Y)\operatorname{mc}(X,Y) be the number of matching characters in strings XX and YY.

Find:

$$\min\{\operatorname{mc}(A,C),\operatorname{mc}(B,C)\}$$

Output the answer modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.

The next TT lines each contain a positive integer NN.

Output Format

For each test case, output one line: the minimum number of times Xiao Y steps on the paint, i.e. $\min\{\operatorname{mc}(A,C),\operatorname{mc}(B,C)\}$.

Output the answer modulo 109+710^9+7.

1
1
1
3
494699
494699494699
494699494699494699
994161775
899186285
348815909

Hint

Explanation for sample 11:

  • A=101A=\texttt{101};
  • B=010B=\texttt{010};
  • C=001C=\texttt{001};
  • mc(A,C)=2\operatorname{mc}(A,C)=2;
  • mc(B,C)=1\operatorname{mc}(B,C)=1;
  • $\min\{\operatorname{mc}(A,C),\operatorname{mc}(B,C)\}=1$.

Test Point ID TT \le NN \le Score
11 1010 5050
22 10510^5 101810^{18}

For 100%100\% of the testdata, 1T1051 \le T \le 10^{5}, 1N10181 \le N \le 10^{18}.

Hint: V3(X)V_3(X) is the number of prime factors 33 in XX. For example, V3(14)=0V_3(14)=0, V3(18)=2V_3(18)=2.

Translated by ChatGPT 5