P10004 [CTT Mutual Test 2023] Permutation Counting 2
Description
Given $n$, for each pair $x,y\in [0,n)$, find how many permutations $p$ of $1\sim n$ satisfy the following conditions:
- $\sum\limits_{i=1}^{n-1}[p_i
Input Format
One line with two integers, $n,MOD$.
Output Format
Output $n$ lines, each containing $n$ integers. The number in row $i$ and column $j$ denotes the answer when $x=i-1,y=j-1$.
Explanation/Hint
For $100\%$ of the testdata, $1\le n\le 500$, $10^9\le MOD\le 1.01\times 10^9$, and $MOD$ is guaranteed to be prime.
$\operatorname{Subtask} 1(10\%):n\le 8$.
$\operatorname{Subtask} 2(15\%):n\le 16$.
$\operatorname{Subtask} 3(25\%):n\le 40$.
$\operatorname{Subtask} 4(25\%):n\le 100$.
$\operatorname{Subtask} 5(25\%):$ No special constraints.
Translated by ChatGPT 5