#P5400. [CTS2019] 随机立方体
[CTS2019] 随机立方体
Description
There is an cube. Each cell in the cube contains a number. If the number in a cell is greater than the numbers in all other cells that share at least one coordinate (in 3D) with it, then we call it a maximal cell.
Now place the numbers from to into the cells uniformly at random (that is, each number is equally likely to appear in any cell), with each number appearing exactly once. Find the probability that there are exactly maximal numbers. Output the answer modulo (a prime).
Input Format
The input contains multiple test cases. The first line contains a positive integer , the number of test cases.
The next lines each contain four positive integers , representing one query.
Output Format
For each query, output one line with one integer, the remainder of the answer modulo .
It can be proven that the answer is always a rational number. Suppose it is (where and are coprime positive integers, and the testdata guarantees that is not a multiple of ). Then you need to output a number such that and . It can be proven that such an exists and is unique.
5
1 1 1 1
2 2 2 1
7 8 9 3
123 456 789 1
1000 1000 1000 10
1
142606337
736950806
246172965
189652652
10
4975401 4951343 4803566 22
4499697 4989534 4995301 89
4960387 4800714 4985451 20
4549943 4925900 4582735 36
3010525 4611932 4998770 67
4980964 4865325 4531707 55
2953628 4962026 4999540 52
4599954 4988700 4817773 75
4981351 4950027 4852696 16
4695981 4993997 4953978 2
856105281
423884937
154402492
813209966
683750161
337149076
838552619
849850633
605653899
384868262
Hint
For of the testdata, , , and .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , and among them, of all testdata guarantees .
For of the testdata, , and among them, of all testdata guarantees .
For of the testdata, , , and .
Among them, of the testdata guarantees .
Translated by ChatGPT 5
京公网安备 11011102002149号