#P5915. 冬至

    ID: 4121 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学递推矩阵加速,矩阵优化快速傅里叶变换 FFT

冬至

Description

You are given the integers 1k1 \sim k. You may choose numbers from them to form a string of length nn (repetition is allowed), and no substring is allowed to be a permutation of 1k1 \sim k.

Find the total number of valid strings modulo 998244353998244353.

Input Format

A single line with two positive integers n,kn, k.

Output Format

A single line with one integer, the total number of valid strings modulo 998244353998244353.

3 2
2
7 7
818503
114514 233
782307368

Hint

[Sample 1 Explanation]
The valid strings that can be formed are: 1,1,11,1,1 and 2,2,22,2,2.
All others are invalid, because they contain a permutation of 121 \sim 2. Therefore, the answer is 22.

[Sample 2 Explanation]
There are 777^7 strings in total. Among them, 7!7! are invalid (i.e. the number of permutations of 171 \sim 7).
So the answer is 777!7^7-7!, which is 818503818503.

[Constraints]
For all testdata, 1k1041\le k \le 10^4, 1n1091\le n \le 10^9.

By: Bike (毕克).

Translated by ChatGPT 5