#P6043. 「ACOI2020」修学旅行
「ACOI2020」修学旅行
Background

Not long after the first semester begins, everyone in Class E is going on a study trip.
Problem Description
Now, six people—Akabane Karma, Sugino Tomohito, Okuda Manami, Kayano Kaede, Kanzaki Yukiko, and Shiota Nagisa—form a group. They will go on an assassination trip in Kyoto. Their goal is still to snipe and kill their teacher. The government has also sent a professional sniper, "Akame no Eye". While completing the mission, they want the happiness value to be as large as possible.
The clever Kanzaki Yukiko (Kanzaki Yukiko) finally worked out the expression for the happiness value. Shockingly, the happiness value is actually related to the number of sightseeing spots in the trip and the number of times they assassinate their teacher.
Suppose they pass through sightseeing spots and assassinate their teacher times, and define:
$$\Gamma(a,b)=\left\{ \begin{aligned} & 1,a>b&\\ & \prod_{i=a}^b i,a \le b&\\ \end{aligned} \right.$$Then the happiness value is:
$$\sum_{i=0}^m \lgroup \frac{\sqrt{\sum_{j=0}^i (C_i^j)^2C_{n+2i-j}^{2i}}}{\Gamma(n+1,n+i)} \times \Gamma(n-i+1,n) \rgroup$$We guarantee that $\frac{\sqrt{\sum_{j=0}^i (C_i^j)^2C_{n+2i-j}^{2i}}}{\Gamma(n+1,n+i)} \times \Gamma(n-i+1,n)$ is an integer.
Now they have questions to ask you. If they pass through sightseeing spots and assassinate their teacher times, can you tell them the happiness value?
Since the answer may be very large, output the answer modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
There is only one line with two integers and .
Output Format
For each test case, output one line containing one integer: the happiness value modulo when they pass through sightseeing spots and assassinate their teacher times.
The sample has been updated.
5
5 3
7 3
9 6
100 50
44 22
26
64
466
41441083
461961723
Hint
Constraints
This problem uses bundled testdata.
- Subtask 1 (10 points): , .
- Subtask 2 (20 points): , .
- Subtask 3 (30 points): , .
- Subtask 4 (40 points): No special constraints on the testdata.
For of the testdata, , , .
Notes
The time limit is 2 s for the test points in the third subtask, and 5 s for the test points in the fourth subtask.
Translated by ChatGPT 5