P15971 [Aboi 2077] Permutation Counting 3

Background

![](https://cdn.luogu.com.cn/upload/image_hosting/bxbae79z.png)

Description

Given $n$, for each pair $x \in [0, n)$ and $y \in [1, n]$, find how many permutations $p$ of $1 \sim n$ satisfy the following conditions: - $\sum\limits_{i=1}^{n-1} [p_i < p_{i+1}] = x$. - There are exactly $y$ permutation cycles in $p$. Take the answer modulo the given prime $P$.

Input Format

One line with two positive integers $n, P$.

Output Format

Output $n$ lines, each containing $n$ integers. The number in row $i$ and column $j$ represents the answer when $x = i - 1$ and $y = j$.

Explanation/Hint

Constraints: For all testdata, $1 \le n \le 200$, $9.9 \times 10^8 \le P \le 1.01 \times 10^9$, and $P$ is guaranteed to be prime. [Click here to view another version of this problem](https://www.luogu.com.cn/problem/U489770)。 Translated by ChatGPT 5