QOJ.ac

QOJ

Time Limit: 0.2 s Memory Limit: 512 MB Total points: 100

#13456. Yet Another Permutation Problem

统计

给定一个长度为 $n$ 的排列 $[1,2,\ldots,n]$,你可以进行以下操作:

  • 选择一个数,将其取出然后放到排列的开头或末尾。

对每个 $k=0,1,\ldots,n-1$,求出进行至多 $k$ 次操作可能得到的排列个数。由于这些数可能非常大,你只需要回答它们除以 $m$ 的余数即可。

输入格式

一行两个整数 $n,m$($1\le n\le 1000$,$10^8\le m\le 10^9+9$,$m$ 是素数)。

输出格式

$n$ 行,第 $i$ 行一个整数表示 $k=i-1$ 时的答案。

样例数据

样例 1 输入

3 998244353

样例 1 输出

1
5
6

样例 1 解释

$n=3$ 时,进行至多 $1$ 次操作可以得到除 $[3,2,1]$ 外的所有排列。

样例 2 输入

1 100000007

样例 2 输出

1

样例 3 输入

20 1000000009

样例 3 输出

1
39
1100
26220
554040
10581480
184187520
930255982
586386822
781249333
374807160
139825602
462558935
67876942
578348054
201415654
108018732
350356788
280522125
280522126

样例 3 解释

注意答案需要对 $m$ 取模。

子任务

Subtask #1 (10 points): $n\le 10$。

Subtask #2 (10 points): $n\le 18$。

Subtask #3 (10 points): $n\le 50$。

Subtask #4 (30 points): $n\le 300$。

Subtask #5 (40 points): 无额外限制。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.