#abc299h. Ex - Dice Sum Infinity

Ex - Dice Sum Infinity

Score : 600600 points

问题描述

Takahashi 拥有一枚无偏向的六面骰子和一个小于 10910^9 的正整数 RR。每次投掷骰子时,它会独立且等概率地显示出数字 1,2,3,4,5,61,2,3,4,5,6,与其他试验的结果无关。

Takahashi 将执行以下步骤。最初,C=0C=0

  1. 投掷骰子并将 CC 增加 11
  2. XX 为目前为止所显示数字的总和。如果 XRX-R10910^9 的倍数,则结束该过程。
  3. 返回步骤 1。

求在该过程结束时 CC 的期望值,结果对 998244353998244353 取模。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

1

Sample Output 1

291034221

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

Sample Input 2

720357616

Sample Output 2

153778832

update @ 2024/3/10 12:25:22