题目描述
Let S=S1S2⋯Sn be a string of length n. For indices 1≤l≤r≤n, let S[l..r] denote the substring SlSl+1⋯Sr.
For 1≤l≤n, the prefix S[1..l] is said to be unique if it occurs in S only as a prefix; that is, there is no index p with 2≤p≤n−l+1 satisfying S[p..p+l−1]=S[1..l].
The prefix S[1..n]=S is always unique, so every string has at least one unique prefix. Define the uniqueness u(S) of S as the length of its shortest unique prefix,
u(S)=min{l:1≤l≤n, S[1..l] is unique},
so that 1≤u(S)≤n for every S.
Given three integers n, k, and p, consider the kn strings of length n over an alphabet of k distinct symbols. Compute
(S∑u(S))modp,
where the sum is taken over all kn such strings.
输入格式
A single line containing three integers n, k, and p.
1≤n≤80, 1≤k≤100, 108≤p≤109. It is not guaranteed that p is prime.
输出格式
A single integer: the value of (∑Su(S))modp.
样例输入 #1
2 3 998244353
样例输出 #1
12
样例输入 #2
3 1 998244353
样例输出 #2
3
样例输入 #3
20 5 998244353
样例输出 #3
311627017