#P7145. [THUPC 2021 初赛] 合法序列
[THUPC 2021 初赛] 合法序列
Problem Description
For a - sequence of length , we number its bits from left to right starting from , denoted as .
Given a positive integer , take a subsegment of with length . Interpret this subsegment as a -bit binary number with the left side as the most significant bit and the right side as the least significant bit, denoted as . Then .
There are subsegments of length in . If for every such subsegment, after interpreting it as the binary number as above, the bit of with index (that is, ) is , then is called legal. It is guaranteed that , so will not go out of range as an index of .
Given , find the number of legal sequences . Since the number of solutions may be large, you only need to output the result modulo .
Input Format
The input contains one line with two positive integers separated by a space.
It is guaranteed that , .
Output Format
Output one line containing one non-negative integer, which is the number of legal solutions modulo .
4 2
2
Hint
Sample Explanation #1
There are two sequences that satisfy the requirement: and .
Source
From the preliminary round of the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).
Resources such as the editorial can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5