atcoder#AGC050D. [AGC050D] Shopping
[AGC050D] Shopping
Score : points
Problem Statement
There are people numbered through , and items numbered through . They play a turn-based game. Person takes the first turn, Person takes the next turn, then Person , , Person , then Person again, , Person , Person again, , and so on, until all items are taken.
In each turn, the following happens:
- If the person already wins an item, nothing happens.
- Otherwise, he chooses one of the items he hasn't chosen yet uniformly at random, and secretly tells it to Snuke, the judge of the game. If the item is already taken by someone else, nothing happens; otherwise he wins the item.
For each , compute the probability that Person wins an item, modulo (as described in the Notes section).
Notes
- All random choices are made independently.
- We can prove that the game always ends in finite number of steps.
- We can also prove that, whenever a player is asked to choose an item, he has at least one item he hasn't chosen yet.
- We can also prove that the probabilities are rational numbers. When you print a probability, first write it as a fraction , where are integers and is not divisible by (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer between and , inclusive, that satisfies .
Constraints
- All values in the input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. On the -th line, print the probability that the -th person wins an item, modulo .
3 2
1
249561089
748683265
- First, Person chooses an item (call it Item ), and wins it.- Then, with probability, Person chooses the other item in the next turn and wins it, and the game ends.
- With probability, Person chooses , he doesn't win it, and Person takes the next turn.- With probability, Person chooses the other item, wins it, and the game ends.
- With probability, Person chooses again. Then, next turn is Person 's and nothing happens because he has already won an item. Then, in the next turn, Person chooses the other item for sure because he has already chosen in his previous turn, so he wins an item this time, and the game ends.
- Then, with probability, Person chooses the other item in the next turn and wins it, and the game ends.
- With probability, Person chooses , he doesn't win it, and Person takes the next turn.
- With probability, Person chooses the other item, wins it, and the game ends.
- With probability, Person chooses again. Then, next turn is Person 's and nothing happens because he has already won an item. Then, in the next turn, Person chooses the other item for sure because he has already chosen in his previous turn, so he wins an item this time, and the game ends.
To summarize, Person will get an item with probability , respectively.
4 3
1
314262112
767169272
915057324
The probabilities are .
40 10
1
868517173
27621563
837064957
222682471
512462123
662169358
927654899
421237429
47896491
462367772
888812171
300869511
63754652
144548024
358216674
895724239
274552277
722622637
946769993
579325471
777654313
142897955
607284898
8038340
863909530
63295741
862961672
335905745
944425523
358698956
299986928
847582651
197657467
180361665
412489246
762713624
410322243
646538576
79047758