#P5915. Forbidden Permutation Substring

    ID: 19141 Type: Default 1000ms 256MiB

Forbidden Permutation Substring

Forbidden Permutation Substring

You are given two integers n and k. You have the numbers \(1,2,\dots,k\) available. You need to form a string (or sequence) of length \(n\) by choosing numbers (repetition allowed) from \(1\) to \(k\), with the restriction that no contiguous substring is a permutation of \(\{1, 2, \dots, k\}\) (i.e. no substring of length \(k\) should contain every number from 1 to \(k\) exactly once).

Output the total number of valid strings modulo \(998244353\).

Note: If \(n < k\) then there is no contiguous substring of length \(k\) and any string is valid.

inputFormat

The input consists of a single line with two space‐separated integers \(n\) and \(k\):

n k

where \(n\) is the length of the string and \(k\) specifies the set \(\{1,2,\dots,k\}\).

outputFormat

Output a single integer: the number of valid strings modulo \(998244353\).

sample

3 1
0