#P11658. 「FAOI-R5」波特检测
「FAOI-R5」波特检测
Background
Verifying whether you are a real person. This may take a few seconds.
Problem Description
Little H is a bot. He has a built-in sequence and a binary string of length . If you ask him about an interval , he can give a set :
- Define a sequence . For , do the following:
- If , then (i.e., Little H cannot change the value of ).
- If , he may choose any non-negative integer and set (i.e., Little H may change the value of arbitrarily, and the modified value does not have to be within ).
- $g(l,r)=\{B_l\operatorname{xor}B_{l+1},B_{l+1}\operatorname{xor}B_{l+2},\cdots,B_{r-1}\operatorname{xor}B_{r}\}$.
Meowzai Milk needs to perform several tests on Little H. In each test, two intervals and are chosen such that , and Meowzai Milk asks Little H and obtains and . If , then the test fails, and Little H’s bot identity will be exposed.
If Little H has a strategy to answer all possible queries such that no test ever fails (that is, for any intervals and satisfying , the test will not fail), then we call the binary string "usable".
Given , each term of the sequence is chosen independently and uniformly at random from . You need to compute the expected number of "usable" binary strings . Output the answer modulo .
Input Format
A single line with two non-negative integers , representing the length of the sequence and the size of the value range.
Output Format
A single line with one non-negative integer, representing the expected number of "usable" binary strings modulo .
If you do not know how to take a rational number modulo:
- Let . It can be proven that the answer can be written as an irreducible fraction , where and are positive integers and . You only need to output a non-negative integer such that .
- If you do not know how to find such an , you may refer to P2613.
1 0
2
2 1
4
3 1
499122184
5 2
655097885
10 3
972670600
114 514
802524221
Hint
Explanation for Sample 1
The only possible case is . Then both and are "usable", so the answer is .
Explanation for Sample 2
There are possible cases:
- .
- .
- .
- .
Without any modification, all of them can pass the test (the corresponding answers are all ), so the answer is .
Explanation for Sample 3
There are possible cases:
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
- , the number of valid is .
When , is not "usable". When querying and :
- Little H can only keep unchanged each time.
- When querying , .
- When querying , .
- , so the test fails.
When , is "usable". When querying and :
- Little H may modify the values of arbitrarily, and the modified values may be different for each query.
- When querying , Little H sets , so .
- When querying , Little H sets , so .
- , so the test succeeds.
Therefore, the answer is $(7\times 4+8\times 4)\times\dfrac{1}{8}=\dfrac{15}{2}$.
Note that , so the answer is .
Explanation for Sample 4
The answer is .
Constraints and Notes
This problem uses bundled subtasks.
- Subtask 1 (10 pts): .
- Subtask 2 (10 pts): and .
- Subtask 3 (10 pts): and .
- Subtask 4 (10 pts): and .
- Subtask 5 (20 pts): .
- Subtask 6 (20 pts): .
- Subtask 7 (20 pts): no special restrictions.
For all testdata, and .
Translated by ChatGPT 5