AtCoder Grand Contest 052
C
Nondivisible Prefix Sums
AtCoder
⌀ 2936
原题
← BD →
翻译中…

Problem Statement

翻译中…

You are given a prime number $P$, which you don't like.

翻译中…

Let's call an array of integers $A_1, A_2, \dots, A_N$ good, if it is possible to reorder the elements in such a way that no prefix sum is divisible by $P$ (that is, there is no $i$ with $1 \le i \le N$ and $A_1 + A_2 + \dots + A_i \equiv 0 \bmod P$ after the reordering).

翻译中…

Consider all $(P-1)^N$ arrays of length $N$ with elements from $1$ to $P-1$. How many of them are good?

翻译中…

As this number can be very big, output it modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $1 \le N \le 5000$
  • $2 \le P \le 10^8$
  • $P$ is a prime.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N P

翻译中…

Output

翻译中…

Output the number of good arrays modulo $998244353$.

翻译中…

样例

Input #1
2 5
Output #1
12
There are $12$ good arrays: $[1, 1]$, $[1, 2]$, $[1, 3]$, $[2, 1]$, $[2, 2]$, $[2, 4]$, $[3, 1]$, $[3, 3]$, $[3, 4]$, $[4, 2]$, $[4, 3]$, $[4, 4]$.
Input #2
4 3
Output #2
8
There are $8$ good arrays: $[1, 1, 1, 2]$, $[1, 1, 2, 1]$, $[1, 2, 1, 1]$, $[2, 1, 1, 1]$, $[2, 2, 2, 1$], $[2, 2, 1, 2]$, $[2, 1, 2, 2]$, $[1, 2, 2, 2]$.
Input #3
5000 99999989
Output #3
51699346
Input #4
2021 307
Output #4
644635349
题目信息
题号
agc052_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。