atcoder#ABC275E. [ABC275E] Sugoroku 4
[ABC275E] Sugoroku 4
Score : points
Problem Statement
Takahashi is playing sugoroku, a board game.
The board has squares, numbered to . Takahashi starts at square and goes for square .
The game uses a roulette wheel with numbers from to that appear with equal probability. Takahashi spins the wheel and moves by the number of squares indicated by the wheel. If this would send him beyond square , he turns around at square and goes back by the excessive number of squares.
For instance, assume that and Takahashi is at square . If the wheel shows , the excessive number of squares beyond square is . Thus, he goes back by three squares from square and arrives at square .
When Takahashi arrives at square , he wins and the game ends.
Find the probability, modulo , that Takahashi wins when he may spin the wheel at most times.
How to print a probability modulo $998244353$
It can be proved that the sought probability is always a rational number. Additionally, under the Constraints of this problem, when the sought probability is represented as an irreducible fraction , it is guaranteed that is not divisible by .
Here, there is a unique integer between and such that . Print this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
2 2 1
499122177
Takahashi wins in one spin if the wheel shows . Therefore, the probability of winning is .
We have , so the answer to be printed is .
10 5 6
184124175
100 1 99
0