102997: [Atcoder]ABC299 Ex - Dice Sum Infinity

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

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

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

  1. Cast the die and increment $C$ by $1$.
  2. Let $X$ be the sum of the numbers shown so far. If $X-R$ is a multiple of $10^9$, quit the procedure.
  3. Go back to step 1.

Find the expected value of $C$ at the end of the procedure, modulo $998244353$.

Notes

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

Constraints

  • $0\lt X\lt10^9$
  • $X$ is an integer.

Input

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

$X$

Output

Print a single line containing the answer.


Sample Input 1

1

Sample Output 1

291034221

The expected value of $C$ at the end of the procedure is approximately $833333333.619047619$, and $291034221$ when represented modulo $998244353$.


Sample Input 2

720357616

Sample Output 2

153778832

Input

题意翻译

高桥有一个小于 $10^9$ 的正整数 $R$ 和一个质地均匀的正方体骰子,每次掷出骰子都会等概率掷出 $1,2,3,4,5,6$ 中的一个数,且每次掷骰子互不影响。 设 $X$ 为当前掷出的数的总和。高桥将会不断地掷骰子,直到当前 $X-R$ 为 $10^9$ 的倍数时停止。 求掷骰子次数 $C$ 的期望,对 $998244353$ 取余。 具体地,设结果可以表示为既约分数 $\dfrac pq$ 的形式,则输出满足 $xq\equiv p\pmod{998244353}$ 的 $x$,其中 $0\le x<998244353$。可以证明 $x$ 是唯一的。

Output

得分:$600$分 部分 问题描述 Takahashi 有一个公正的六面骰子和一个小于 $10^9$ 的正整数 $R$。 每次投掷骰子时,它将以相等的概率显示数字 $1,2,3,4,5,6$,与其他试验的结果无关。 Takahashi 将执行以下程序。 最初,$C=0$。 1. 投掷骰子并将 $C$ 增加 $1$。 2. 让 $X$ 为迄今为止显示的数字的总和。如果 $X-R$ 是 $10^9$ 的倍数,退出程序。 3. 回到步骤 1。 在程序结束时找到 $C$ 的期望值,对 $998244353$ 取模。 注释 在本问题的约束下,可以证明 $C$ 的期望值表示为不可约分数 $p/q$,且存在一个唯一的整数 $x\ (0\leq x\lt998244353)$,满足 $xq \equiv p\pmod{998244353}$。 打印这个 $x$。 约束 * $0\lt R\lt10^9$ * $R$ 是一个整数。 输入/输出格式 输入 输入从标准输入按以下格式给出: $R$ 输出 打印一行答案。 样例输入 1 1 样例输出 1 291034221 在程序结束时,$C$ 的期望值约为 $833333333.619047619$,对 $998244353$ 取模后为 $291034221$。 样例输入 2 720357616 样例输出 2 153778832

加入题单

算法标签: