Codeforces Global Round 24
D
Doremy's Pegging Game
Codeforces
2000
原题
← CE →
翻译中…

Doremy has $n+1$ pegs. There are $n$ red pegs arranged as vertices of a regular $n$-sided polygon, numbered from $1$ to $n$ in anti-clockwise order. There is also a blue peg of slightly smaller diameter in the middle of the polygon. A rubber band is stretched around the red pegs.

翻译中…

Doremy is very bored today and has decided to play a game. Initially, she has an empty array $a$. While the rubber band does not touch the blue peg, she will:

翻译中…
  1. choose $i$ ($1 \leq i \leq n$) such that the red peg $i$ has not been removed;
  2. remove the red peg $i$;
  3. append $i$ to the back of $a$.
翻译中…

Doremy wonders how many possible different arrays $a$ can be produced by the following process. Since the answer can be big, you are only required to output it modulo $p$. $p$ is guaranteed to be a prime number.

翻译中…

image game with $n=9$ and $a=[7,5,2,8,3,9,4]$ and another game with $n=8$ and $a=[3,4,7,1,8,5,2]$

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $p$ ($3 \leq n \leq 5000$, $10^8 \le p \le 10^9$) — the number of red pegs and the modulo respectively.

翻译中…

$p$ is guaranteed to be a prime number.

翻译中…

Output

翻译中…

Output a single integer, the number of different arrays $a$ that can be produced by the process described above modulo $p$.

翻译中…

Note

翻译中…

In the first test case, $n=4$, some possible arrays $a$ that can be produced are $[4,2,3]$ and $[1,4]$. However, it is not possible for $a$ to be $[1]$ or $[1,4,3]$.

翻译中…

样例

Input #1
4 100000007
Output #1
16
InputCopy OutputCopy
Input #2
1145 141919831
Output #2
105242108
InputCopy OutputCopy
题目信息
题号
1764D
时间限制
1.5 s
内存限制
512 MB
标签
组合数学
动态规划
数学

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