QOJ.ac

QOJ

Límite de tiempo: 0.2 s Límite de memoria: 512 MB Puntuación total: 100

#13456. Yet Another Permutation Problem

Estadísticas

Given a permutation $[1, 2, \ldots, n]$ of length $n$, you can perform the following operation:

  • Choose a number, remove it, and place it at either the beginning or the end of the permutation.

For each $k=0, 1, \ldots, n-1$, find the number of permutations that can be obtained by performing at most $k$ operations. Since these numbers can be very large, you only need to output their values modulo $m$.

Input

A single line containing two integers $n$ and $m$ ($1\le n\le 1000$, $10^8\le m\le 10^9+9$, $m$ is a prime number).

Output

$n$ lines, where the $i$-th line contains an integer representing the answer for $k=i-1$.

Examples

Input 1

3 998244353

Output 1

1
5
6

Note 1

For $n=3$, all permutations except $[3, 2, 1]$ can be obtained by performing at most $1$ operation.

Input 2

1 100000007

Output 2

1

Input 3

20 1000000009

Output 3

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

Note 3

Note that the answers must be taken modulo $m$.

Subtasks

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): No additional constraints.

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.