#P7289. 「EZEC-5」「KrOI2021」Chasse Neige
「EZEC-5」「KrOI2021」Chasse Neige
Background

"I like snow."
"Although I used to hate the cold, now it is my favorite."

Problem Description
Rikka gives you queries. In each query, two positive integers are given. You need to tell Rikka how many permutations of length satisfy the following conditions:
-
.
-
.
-
There exist exactly positions such that and .
Output the answer modulo .
Input Format
The first line contains two integers , representing the number of queries and the upper bound of the range of .
The next lines each contain two integers , with the meaning as described above.
Output Format
Output lines. Each line contains one positive integer, the answer modulo .
2 10
3 1
5 2
2
16
Hint
Sample Explanation 1
For the first query, . Both and satisfy the conditions, so the answer is .
For the second query, the permutations that satisfy the conditions are:
$$(1,3,2,5,4),(1,4,2,5,3),(1,4,3,5,2),(1,5,2,4,3),(1,5,3,4,2)\\(2,3,1,5,4),(2,4,1,5,3),(2,4,3,5,1),(2,5,1,4,3),(2,5,3,4,1)\\(3,4,1,5,2),(3,4,2,5,1),(3,5,1,4,2),(3,5,2,4,1),(4,5,1,3,2),(4,5,2,3,1)$$There are in total, so the answer is .
Constraints
| Subtask ID | Points | Other Constraints | ||
|---|---|---|---|---|
| Subtask 1 | ||||
| Subtask 2 | ||||
| Subtask 3 | ||||
| Subtask 4 | ||||
| Subtask 5 | and is odd | |||
| Subtask 6 | ||||
| Subtask 7 | ||||
For of the testdata, , , and $\max(1,\lfloor\frac{n-1}{2}\rfloor-10) \leq k \leq \lfloor\frac{n-1}{2}\rfloor$.
Translated by ChatGPT 5