atcoder#ABC263E. [ABC263E] Sugoroku 3
[ABC263E] Sugoroku 3
Score : points
Problem Statement
There are squares called Square though Square . You start on Square .
Each of the squares from Square through Square has a die on it. The die on Square is labeled with the integers from through , each occurring with equal probability. (Die rolls are independent of each other.)
Until you reach Square , you will repeat rolling a die on the square you are on. Here, if the die on Square rolls the integer , you go to Square .
Find the expected value, modulo , of the number of times you roll a die.
Notes
It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented using two coprime integers and , there is a unique integer such that and . Find this .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 1
4
The sought expected value is , so should be printed.
Here is one possible scenario until reaching Square :
- Roll on Square , and go to Square .
- Roll on Square , and stay there.
- Roll on Square , and go to Square .
This scenario occurs with probability .
5
3 1 2 1
332748122