CF1764D.Doremy's Pegging Game

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:512MB

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 (1≤i≤n1 \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]

Doremy 有 n+1n+1 个钉子。其中有 nn 个红色钉子,它们构成一个正 nn 边形的顶点,按逆时针方向编号为 11 到 nn。此外,在该正 nn 边形的中心还有一个直径略小的蓝色钉子。一根橡皮筋被绷紧在所有红色钉子上。

Doremy 今天非常无聊,决定玩一个游戏。初始时,她有一个空数组 aa。只要橡皮筋尚未接触到蓝色钉子,她就会重复执行以下操作:

  1. 选择一个下标 ii(1≤i≤n1 \leq i \leq n),使得红色钉子 ii 尚未被移除;
  2. 移除红色钉子 ii;
  3. 将 ii 追加到数组 aa 的末尾。

Doremy 想知道:通过上述过程,一共可能产生多少种不同的数组 aa?由于答案可能很大,你只需输出其对模数 pp 取模的结果。题目保证 pp 是一个质数。

左图:n=9n=9 且 a=[7,5,2,8,3,9,4]a=[7,5,2,8,3,9,4];右图:n=8n=8 且 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 (3≤n≤50003 \leq n \leq 5000, 108≤p≤10910^8 \le p \le 10^9) — the number of red pegs and the modulo respectively.

pp is guaranteed to be a prime number.

第一行包含两个整数 nn 和 pp(3≤n≤50003 \leq n \leq 5000,108≤p≤10910^8 \le p \le 10^9)—— 分别表示红色钉子的数量和模数。

pp 保证为质数。

输出格式

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

输出一个整数,表示通过上述过程能够生成的不同数组 aa 的数量对 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].

在第一个测试用例中,n=4n=4,一些可能生成的数组 aa 包括 [4,2,3][4,2,3] 和 [1,4][1,4]。然而,aa 不可能为 [1][1] 或 [1,4,3][1,4,3]。

输入解题思路,AI测评打分。不知道怎么写?

首页