#P16810. [蓝桥杯 2026 国 Python A] 亮灭反转
[蓝桥杯 2026 国 Python A] 亮灭反转
Problem Description
In front of Xiao Lan, there are lamps in a row. Each lamp is initially either on or off. Therefore, there are different initial states in total.
For a certain initial state, Xiao Lan will make independent observations. Each observation starts directly from the same initial state (the observations do not affect each other):
- Observation : Do not change the state of any lamp, and record the number of lamps that are on in the whole row at this time.
- Observation (): Based on the initial state, first flip the states of the first lamps (on becomes off, off becomes on), then record the number of lamps that are on in the whole row at this time.
Let the numbers of lamps that are on obtained in these observations be in order. If, in the sequence , the number of distinct elements is exactly , then this initial state is called good.
Now, please help Xiao Lan compute how many good initial states there are in total. Since the answer may be very large, you only need to output the result modulo .
Input Format
Input one line containing two integers and , separated by a single space.
Output Format
Output one integer, representing the number of valid initial states modulo .
3 2
2
Hint
Sample Explanation
When , there are valid initial states that meet the requirement, namely “off, on, off” and “on, off, on”:
If the initial state is “off, on, off”, then the sequence of numbers of lamps that are on after each observation is . The distinct elements are and , so there are kinds.
If the initial state is “on, off, on”, then the sequence is . The distinct elements are and , so there are kinds.
It can be verified that only these initial states satisfy the condition that the number of distinct elements is exactly .
Constraints
For of the testdata, .
For of the testdata, , .
For all testdata, , .
Translated by ChatGPT 5