#P3750. [六省联考 2017] 分手是祝愿
[六省联考 2017] 分手是祝愿
Description
Zeit und Raum trennen dich und mich. Time and space separate you and me.
B-kun is playing a game with lights and switches. The lights have initial states and are indexed by the positive integers from to .
Each light has two states, on and off. We use to indicate the light is on and to indicate it is off. The goal of the game is to turn all lights off.
When operating the -th switch, the states of all lights whose indices are divisors of (including and ) are toggled, i.e., on becomes off, and off becomes on.
B-kun finds this game difficult, so he considers the following strategy: at each step, uniformly at random choose one switch to operate, until all lights are off.
This strategy may require many operations, so B-kun thinks of the following optimization. If, in the current state, it is possible to turn all lights off by pressing at most switches, then he will stop acting randomly and directly choose a method with the minimum number of operations (which is clearly at most ) to press those switches.
B-kun wants to know the expected number of operations under this strategy (that is, act randomly first, and finally, if at most steps suffice, use the method with the minimum number of operations).
This expectation may be large, but B-kun observes that the expectation multiplied by is always an integer, so he only needs this integer modulo .
Input Format
The first line contains two integers .
The next line contains integers, each being or , where the -th integer indicates the initial state of the -th light.
Output Format
Output one line: the expectation of the number of operations multiplied by , modulo .
4 0
0 0 1 1
512
5 0
1 0 1 1 1
5120
Hint
For of the testdata, the input is identical to the sample.
For an additional of the testdata, .
For an additional of the testdata, .
For an additional of the testdata, .
For of the testdata, .
For each of the above parts of the testdata, half of the testdata satisfies .
Translated by ChatGPT 5
京公网安备 11011102002149号