atcoder#ABC299H. [ABC299Ex] Dice Sum Infinity
[ABC299Ex] Dice Sum Infinity
Score : points
Problem Statement
Takahashi has an unbiased six-sided die and a positive integer less than . Each time the die is cast, it shows one of the numbers with equal probability, independently of the outcomes of the other trials.
Takahashi will perform the following procedure. Initially, .
- Cast the die and increment by .
- Let be the sum of the numbers shown so far. If is a multiple of , quit the procedure.
- Go back to step 1.
Find the expected value of at the end of the procedure, modulo .
Notes
Under the constraints of this problem, it can be shown that the expected value of is represented as an irreducible fraction , and there is a unique integer such that . Print this .
Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print a single line containing the answer.
1
291034221
The expected value of at the end of the procedure is approximately , and when represented modulo .
720357616
153778832