| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 16 초 (추가 시간 없음) | 1024 MB | 2 | 2 | 2 | 100.000% |
We are given integers $n$ and $c$.
A sequence $a_1, a_2, \ldots, a_m$ is good if and only if:
For a good integer sequence $a_1, a_2, \ldots, a_m,ドル let us define
$$f(a) = \sum_{i=1}^{m-1} [a_i > a_{i+1}]\text{.}$$
That is, $f(a)$ denotes the number of indices $i$ that satisfy $a_i > a_{i+1}$ among all 1ドル \leq i \leq m - 1$. We define the weight of the sequence $a$ as the value of $c^{f(a)}$.
Your task is to calculate the sum of the weights of all good sequences, modulo 998ドル,244円,353円$.
The first line contains two integers $n$ and $c$ (1ドル \le n \le 3 \cdot 10^5,ドル 0ドル \leq c < 998,244円,353円$).
Output the answer modulo 998ドル,244円,353円$.
5 3
8
1 0
1
2022 39
273239559
In the first example, all good sequences are as follows:
| $a$ | $f(a)$ | $c^{f(a)}$ |
|---|---|---|
| $[5]$ | 0ドル$ | 1ドル$ |
| $[2, 3]$ | 0ドル$ | 1ドル$ |
| $[3, 2]$ | 1ドル$ | 3ドル$ |
| $[2, 1, 2]$ | 1ドル$ | 3ドル$ |
So the answer is 1ドル + 1 + 3 + 3 = 8$.