atcoder#ABC299H. [ABC299Ex] Dice Sum Infinity

[ABC299Ex] Dice Sum Infinity

Score : 600600 points

Problem Statement

Takahashi has an unbiased six-sided die and a positive integer RR less than 10910^9. Each time the die is cast, it shows one of the numbers 1,2,3,4,5,61,2,3,4,5,6 with equal probability, independently of the outcomes of the other trials.

Takahashi will perform the following procedure. Initially, C=0C=0.

  1. Cast the die and increment CC by 11.
  2. Let XX be the sum of the numbers shown so far. If XRX-R is a multiple of 10910^9, quit the procedure.
  3. Go back to step 1.

Find the expected value of CC at the end of the procedure, modulo 998244353998244353.

Notes

Under the constraints of this problem, it can be shown that the expected value of CC is represented as an irreducible fraction p/qp/q, and there is a unique integer x (0x<998244353)x\ (0\leq x\lt998244353) such that xqp(mod998244353)xq \equiv p\pmod{998244353}. Print this xx.

Constraints

  • 0<R<1090\lt R\lt10^9
  • RR is an integer.

Input

The input is given from Standard Input in the following format:

RR

Output

Print a single line containing the answer.

1
291034221

The expected value of CC at the end of the procedure is approximately 833333333.619047619833333333.619047619, and 291034221291034221 when represented modulo 998244353998244353.

720357616
153778832