#abc300e. E - Dice Product 3

E - Dice Product 3

Score : 500500 points

问题陈述

你有一个整数 11 和一枚骰子,骰子掷出的整数在 1166(包括两端点)之间,并且每个整数出现的概率相等。
当你手中的整数严格小于 NN 时,重复执行以下操作:

  • 投掷骰子。若骰子显示数字 xx,则将你的整数乘以 xx

求当你的整数最终变为 NN 时的概率,该概率对 998244353998244353 取模。

如何计算模 998244353998244353 下的概率?我们能够证明所求概率总是有理数。另外,在本题约束条件下,当该概率表示为两个互质整数 PPQQ 的形式 PQ\frac{P}{Q} 时,我们可以证明存在一个唯一的整数 RR,满足 R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} 以及 0R<9982443530 \leq R \lt 998244353。找出这个 RR

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

Problem Statement

You have an integer 11 and a die that shows integers between 11 and 66 (inclusive) with equal probability.
You repeat the following operation while your integer is strictly less than NN:

  • Cast a die. If it shows xx, multiply your integer by xx.

Find the probability, modulo 998244353998244353, that your integer ends up being NN.

How to find a probability modulo 998244353998244353? We can prove that the sought probability is always rational. Additionally, under the constraints of this problem, when that value is represented as PQ\frac{P}{Q} with two coprime integers PP and QQ, we can prove that there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N10182 \leq N \leq 10^{18}
  • NN is an integer.

Input

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

NN

Output

Print the probability, modulo 998244353998244353, that your integer ends up being NN.

Sample Input 1

6

Sample Output 1

239578645

One of the possible procedures is as follows.

  • Initially, your integer is 11.
  • You cast a die, and it shows 22. Your integer becomes 1×2=21 \times 2 = 2.
  • You cast a die, and it shows 44. Your integer becomes 2×4=82 \times 4 = 8.
  • Now your integer is not less than 66, so you terminate the procedure.

Your integer ends up being 88, which is not equal to N=6N = 6.

The probability that your integer ends up being 66 is 725\frac{7}{25}. Since 239578645×257(mod998244353)239578645 \times 25 \equiv 7 \pmod{998244353}, print 239578645239578645.

Sample Input 2

7

Sample Output 2

0

No matter what the die shows, your integer never ends up being 77.

Sample Input 3

300

Sample Output 3

183676961

Sample Input 4

979552051200000000

Sample Output 4

812376310

update @ 2024/3/10 08:24:38