Problem D. Problem D. Permutation

时间限制 2000 ms   内存限制 512 MB

Define the value of a permutation of 1 . . . n as
n
∑|pi - i|
i=1

Given n, p, for every s = 0 . . . n^2-1, count the number of permutations of length n
whose value equals to s.
Output the answer modulo a prime p.
 

输入数据

The first line of the input contains an integer T , denoting the number of test cases.
In each test case, there are two integers n, p in one line, denoting the length of permutations and the modulo.
1 ≤ T ≤ 10, 1 ≤ n ≤ 100, 10^9 < p < 1.1 × 10^9, only two cases’ n > 50, p is a prime.
 

输出数据

For each test case, output one line contains n^2 integer, denoting the number of permutations of length n whose value equals to s = 0 . . . n^2-1 modulo p.
 

样例输入

复制
4
4 1000000223
3 1000000321
2 1000000123
1 1000000447

样例输出

复制
1 0 3 0 7 0 9 0 4 0 0 0 0 0 0 0
1 0 2 0 3 0 0 0 0
1 0 1 0
1

提交

请先 登录

© 2026 FAQs Contact About

Baidu
map