#P6669. [清华集训 2016] 组合数问题
[清华集训 2016] 组合数问题
Description
The binomial coefficient represents the number of ways to choose items from items. For example, choosing two items from the three items can be done in three ways: , , and . According to the definition of binomial coefficients, we have the general formula to compute :
Here, . (In addition, when , .)
Xiaocong wants to know: given , , and , among all and , how many pairs satisfy that is a multiple of .
Output the answer modulo .
Input Format
The first line contains two integers , where is the total number of groups of testdata in this test point.
In the next lines, each line contains two integers .
Output Format
Output lines. Each line contains one integer: among all and , how many pairs satisfy that is a multiple of .
1 2
3 3
1
2 5
4 5
6 7
0
7
3 23
23333333 23333333
233333333 233333333
2333333333 2333333333
851883128
959557926
680723120
Hint
Sample Explanation
Among all cases, only is a multiple of .
Constraints and Notes
For of the test points, .
For another of the test points, .
For another of the test points, .
For another of the test points, .
For of the test points, , , and is a prime number.
Translated by ChatGPT 5
京公网安备 11011102002149号