#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 steps.
HG’s painting rule is: for the -th step from top to bottom, if is odd, then he paints the left half; otherwise, he paints the right half. For the definition of , 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 . That is, Xiao Y has only possible ways to go downstairs.
Output the answer modulo .
Formal Statement
Given three binary strings , all of length . String indices start from .
Where:
- ;
- ;
- ; specifically, the -th character is . For the definition of , see the Hint.
Let be the number of matching characters in strings and .
Find:
$$\min\{\operatorname{mc}(A,C),\operatorname{mc}(B,C)\}$$Output the answer modulo .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain a positive integer .
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 .
1
1
1
3
494699
494699494699
494699494699494699
994161775
899186285
348815909
Hint
Explanation for sample :
- ;
- ;
- ;
- ;
- ;
- $\min\{\operatorname{mc}(A,C),\operatorname{mc}(B,C)\}=1$.
| Test Point ID | Score | ||
|---|---|---|---|
For of the testdata, , .
Hint: is the number of prime factors in . For example, , .
Translated by ChatGPT 5