CF1764D.Doremy's Pegging Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Doremy has n+1n+1 pegs. There are nn red pegs arranged as vertices of a regular nn -sided polygon, numbered from 11 to nn 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 aa . While the rubber band does not touch the blue peg, she will:

  1. choose ii ( 1in1 \leq i \leq n ) such that the red peg ii has not been removed;
  2. remove the red peg ii ;
  3. append ii to the back of aa .

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

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

输入格式

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

pp is guaranteed to be a prime number.

输出格式

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

输入输出样例

  • 输入#1

    4 100000007

    输出#1

    16
  • 输入#2

    1145 141919831

    输出#2

    105242108

说明/提示

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

首页