luogu#P5223. Function

Function

Background

CYJian{\rm CYJian} recently thought of Water Triangle and felt it was too easy, so he came up with a more interesting version.

Problem Description

Given NN and KK, compute:

i=1Kf[N][i] (mod 998244353)\sum_{i=1}^{K} f[N][i] \ (\bmod\ 998244353)

where:

$$f[i][j] = f[i-1][j] + f[i][j-1] + f[i-1][j-1] \ (i>1, j \leq i)$$$$f[1][1] = 1 \qquad f[i][0] = 0 \qquad f[i][j] = 0 \ (j>i)$$

Input Format

The first line contains two positive integers NN and KK.

Output Format

Output one line containing the value of the expression above.

1 1
1

2 2

3

3 3

11

4 3

23

Hint

Constraints:

For 10%10\% of the testdata: 1N1031K1021 \leq N \leq 10^3 \qquad 1 \leq K \leq 10^2.

For 30%30\% of the testdata: 1N1061K1021 \leq N \leq 10^6 \qquad 1 \leq K \leq 10^2.

For 50%50\% of the testdata: 1N10181K1021 \leq N \leq 10^{18} \qquad 1 \leq K \leq 10^2.

For another 20%20\% of the testdata: 1N1061K1031 \leq N \leq 10^6 \qquad 1 \leq K \leq 10^3.

For 100%100\% of the testdata: 1N10181K1031 \leq N \leq 10^{18} \qquad 1 \leq K \leq 10^3.

It is guaranteed that KNK \leq N.

Update: The time limit has been changed as follows: for test points 11~3535, the time limit is 600 ms600 \text{ ms}; for test points 3636~5050, the time limit is 400 ms400 \text{ ms}.

Translated by ChatGPT 5