atcoder#AGC045D. [AGC045D] Lamps and Buttons
[AGC045D] Lamps and Buttons
Score : points
Problem Statement
We have lamps numbered to , and buttons numbered to . Initially, Lamp are on, and the other lamps are off.
Snuke and Ringo will play the following game.
- First, Ringo generates a permutation of . The permutation is chosen from all possible permutations with equal probability, without being informed to Snuke.
- Then, Snuke does the following operation any number of times he likes:
- Choose a lamp that is on at the moment. (The operation cannot be done if there is no such lamp.) Let Lamp be the chosen lamp. Press Button , which switches the state of Lamp . That is, Lamp will be turned off if it is on, and vice versa.
- Choose a lamp that is on at the moment. (The operation cannot be done if there is no such lamp.) Let Lamp be the chosen lamp. Press Button , which switches the state of Lamp . That is, Lamp will be turned off if it is on, and vice versa.
At every moment, Snuke knows which lamps are on. Snuke wins if all the lamps are on, and he will surrender when it turns out that he cannot win. What is the probability of winning when Snuke plays optimally?
Let be the probability of winning. Then, will be an integer. Compute modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print modulo , where is the probability of Snuke's winning.
3 1
2
First, Snuke will press Button . If Lamp turns off, he loses. Otherwise, he will press the button that he can now press. If the remaining lamp turns on, he wins; if Lamp turns off, he loses. The probability of winning in this game is , so we should print .
3 2
3
8 4
16776
9999999 4999
90395416