PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000232. Xác suất nhận được tích N qua xúc xắc (Dice Product 3)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xác suất nhận được tích N qua xúc xắc (Dice Product 3)

Dice Product 3

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Initially you hold the integer X=1X=1 and have a fair six-sided die numbered from 11 through 66. While X<NX<N, roll the die; if it shows yy, replace XX by X⋅yX\cdot y. The process stops once X≥NX\ge N. A roll of 11 does not change XX but is still a legitimate outcome.

Find the probability that the final value equals exactly NN, modulo 998244353998244353.

Precisely, if the probability in lowest terms is P/QP/Q, print the unique integer RR in [0,998244352][0,998244352] satisfying RQ≡P(mod998244353)RQ\equiv P\pmod{998244353}. Existence and uniqueness are guaranteed by the constraints.

Input

The only line contains an integer NN.

Output

Print the integer RR representing the probability that the final integer equals NN, modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 2≤N≤1062\le N\le 10^6.

  • Subtask 2 (30 points): 2≤N≤10122\le N\le 10^{12}.

  • Subtask 3 (50 points): 2≤N≤10182\le N\le 10^{18}.

Examples

Input

6

Output

239578645

Explanation

For N=6N=6, stopping at 66 can occur by rolling 66 directly, or by first reaching 22 then rolling 33, or first reaching 33 then rolling 22. Rolls of 11 leave the current value unchanged and must be accounted for as repeated attempts. Summing the valid paths including such repetitions yields probability 7/257/25. Since 25⋅239578645≡7(mod998244353)25\cdot239578645\equiv7\pmod{998244353}, the required output is 239578645239578645.