atcoder#ARC134F. [ARC134F] Flipping Coins
[ARC134F] Flipping Coins
Score : points
Problem Statement
There are coins numbered arranged in a row. Initially, all coins face up.
Snuke chooses a permutation of with equal probability, and do operations. The -th operation does the following.
- If the coin numbered faces down, do nothing.
- If the coin numbered faces up, turn that coin over and then turn over the coin numbered .
After the operations, Snuke will receive yen (Japanese currency) from his mother, where is the number of coins facing up.
Find the expected value of the amount Snuke will get, multiplied by (it can be proved that this is an integer), modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the expected value of the amount Snuke will get, multiplied by , modulo .
4 2
90
- When , the operations go as follows.- In the -st operation, the coin numbered faces down, and then the coin numbered faces up.
- In the -nd operation, the coin numbered faces down, and then the coin numbered faces down.
- In the -rd operation, the coin numbered faces down, and then the coin numbered faces up.
- In the -th operation, nothing is done.
- In the -st operation, the coin numbered faces down, and then the coin numbered faces up.
- In the -nd operation, the coin numbered faces down, and then the coin numbered faces down.
- In the -rd operation, the coin numbered faces down, and then the coin numbered faces up.
- In the -th operation, nothing is done.
- In the end, two coins face up, so he receives yen.
2 100
10001
200000 12345
541410753
- Be sure to find the value modulo .