#P8005. An Extra Requirement
An Extra Requirement
Description
Given a permutation of length , you may perform the following operation any number of times: choose three positions . If or , then you may delete .
Count the number of permutations for which there exists a way to delete elements so that in the end there are at most two numbers left and . Since the answer may be very large, output the result modulo .
Input Format
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers , representing the length of the permutation and the first number of the permutation, respectively.
Output Format
Output lines, each containing one integer, the answer modulo .
7
3 1
3 2
3 3
4 1
4 2
4 3
4 4
1
2
1
3
5
5
3
5
5 2
6 3
7 4
8 5
9 6
20
104
648
4662
38040
Hint
This problem uses bundled testdata.
| Subtask ID | Score | Special Constraints |
|---|---|---|
| , | ||
| , | ||
| , | ||
| No special constraints. |
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5
京公网安备 11011102002149号