luogu#P4678. [FJWC2018] 全排列
[FJWC2018] 全排列
Problem Description
Define two permutations and of length to be similar if, for all , holds. Here, is the number of indices such that .
For two permutations of length , define the function as the number of pairs such that is similar to , and contains no more than inversion pairs.
Now you need to compute: after letting and range over all permutations of , the sum of all .
Input Format
The first line contains an integer , which denotes the number of test cases.
The next lines each contain two non-negative integers .
Output Format
For each test case, output one integer per line, which is the answer modulo .
4
2 2
2 1
2 0
1 1
10
10
9
1
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, $T \leqslant 10^4, n \leqslant 500, E \leqslant 10^6$.
Translated by ChatGPT 5