A15484 | Doremy's Pegging Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
 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]$
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.
 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]$
输入格式
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.
$p$ is guaranteed to be a prime number.
输出格式
Output a single integer, the number of different arrays $a$ that can be produced by the process described above modulo $p$ .
输入输出样例
输入 #1
4 100000007
输出 #1
16
输入 #2
1145 141919831
输出 #2
105242108
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]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted