Under construction

Still being built. Things may change

Counting Sequence

Time limit16sMemory limit1024 MB

Summary
Count sequences of positive integers with adjacent differences of 1 and sum n, weighting each by c raised to the number of descents, modulo 998244353.
Level

Hard8 of 10

Topics
Dynamic programming, Math, Combinatorics
Solved
No attempts yet

Problem

We are given integers nn and cc.

A sequence a1,a2,…,ama_1, a_2, \ldots, a_m is good if and only if:

  • ai>0a_i > 0 for all 1≤i≤m1 \leq i \leq m,
  • ∣ai+1−ai∣=1|a_{i+1}-a_i|=1 for all 1≤i≤m−11 \leq i \leq m-1,
  • ∑i=1mai=n\sum_{i=1}^m a_i=n.

For a good sequence a1,a2,…,ama_1, a_2, \ldots, a_m, define

f(a)=∑i=1m−1[ai>ai+1].f(a) = \sum_{i=1}^{m-1} [a_i > a_{i+1}].

That is, f(a)f(a) is the number of indices ii with 1≤i≤m−11 \leq i \leq m-1 such that ai>ai+1a_i > a_{i+1}. The weight of a sequence aa is cf(a)c^{f(a)}.

Compute the sum of the weights of all good sequences, modulo 998244353.

Input

The first line contains two integers nn and cc (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5, 0≤c<9982443530 \leq c < 998244353).

Output

Output the answer modulo 998244353.

Hint

In the first example, all good sequences are as follows:

aaf(a)f(a)cf(a)c^{f(a)}
[5][5]0011
[2,3][2, 3]0011
[3,2][3, 2]1133
[2,1,2][2, 1, 2]1133

So the answer is 1+1+3+3=81 + 1 + 3 + 3 = 8.

Examples3

  1. Example 1

    Input
    5 3
    
    Expected output
    8
    
  2. Example 2

    Input
    1 0
    
    Expected output
    1
    
  3. Example 3

    Input
    2022 39
    
    Expected output
    273239559