atcoder#ABC300E. [ABC300E] Dice Product 3
[ABC300E] Dice Product 3
Score : points
Problem Statement
You have an integer and a die that shows integers between and (inclusive) with equal probability. You repeat the following operation while your integer is strictly less than :
- Cast a die. If it shows , multiply your integer by .
Find the probability, modulo , that your integer ends up being .
How to find a probability modulo $998244353$?
We can prove that the sought probability is always rational. Additionally, under the constraints of this problem, when that value is represented as \frac{P}{Q} with two coprime integers P and Q, we can prove that there is a unique integer R such that R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353. Find this R.Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the probability, modulo , that your integer ends up being .
6
239578645
One of the possible procedures is as follows.
- Initially, your integer is .
- You cast a die, and it shows . Your integer becomes .
- You cast a die, and it shows . Your integer becomes .
- Now your integer is not less than , so you terminate the procedure.
Your integer ends up being , which is not equal to .
The probability that your integer ends up being is . Since , print .
7
0
No matter what the die shows, your integer never ends up being .
300
183676961
979552051200000000
812376310