Automata Embedding
시간 제한1초메모리 제한1024 MB
길이 n인 문자열 가운데 KMP 실패 링크 오토마타를 평면에 교차 없이 그릴 수 있는 것의 개수를 C가지 문자로 세어 998244353으로 나눈 나머지를 구한다.
문제
For a string of length , let denote the substring consisting of the characters from position to position (where ). Also, the failure function of is defined as follows.
\[f(i) =\max(\{0\}\cup\{j\,\vert\, S[1..j] =S[i-j+1..i] ,\, 1\leq j<i\})\]
The KMP automaton made using the failure function of string denotes the following kind of automaton. The automaton has states , and for each state , there exists exactly one transition from to .
If a KMP automaton can be embedded on a plane, it means that if we map state to a point at on the plane, and draw all transitions as arrows which do not cross the -axis on the plane, it is possible to draw all arrows such that no arrows intersect except when they meet at endpoints.
Using an alphabet consisting of letters, find the number of strings of length whose KMP automaton can be embedded on a plane modulo .

KMP automaton for the string
입력
The first line of input contains two space-separated integers and , denoting the length of the string and the number of letters in the alphabet respectively.
출력
The first line of output should contain the number of strings of length whose KMP automaton can be embedded on a plane modulo .