#P8737. [蓝桥杯 2020 国 B] 质数行者
[蓝桥杯 2020 国 B] 质数行者
Background
Xiao Lan is playing a game called Prime Walker.
Problem Description
The game is played on a 3D grid of size . Rows are numbered from north to south as Row to Row , columns are numbered from west to east as Column to Column , and layers are numbered from bottom to top as Layer to Layer .
Xiao Lan needs to control his character to move from Row , Column , Layer to Row , Column , Layer . At each step, he may move east by a prime number of cells, move south by a prime number of cells, or move up by a prime number of cells. Each time he reaches a position, Xiao Lan’s character must stop there briefly.
There are two traps in the game, located at Row , Column , Layer and Row , Column , Layer . These trap positions may be crossed over, but the character is not allowed to stop on them. That is, Xiao Lan cannot make a move that lands exactly on a trap, but it is allowed for a move to pass over a trap in the middle.
Xiao Lan has been quite free recently, so he wants to finish the game in different ways. Two ways are considered different if the sets of positions where Xiao Lan stops briefly are different.
Please help Xiao Lan compute how many different ways there are in total.
Note: Please pay attention to the memory limit. If your program exceeds the memory limit during execution, it will receive zero points.
Input Format
The first line contains three integers , representing the size of the grid.
The second line contains integers , representing the positions of the traps.
Output Format
Output one line containing one integer, representing the number of ways. The answer may be very large. Please output the remainder of the answer modulo (i.e. ).
5 6 1
3 4 1 1 2 1
11
Hint
Sample Explanation
Use to represent Row , Column , Layer . The possible ways are as follows:
-
.
-
.
-
.
-
.
-
.
-
.
-
.
-
.
-
.
-
.
-
.
Constraints and Assumptions
For of the testdata, .
For of the testdata, .
For all testdata, , , , . The traps are not at the start or the end, and the two traps are different.
Lanqiao Cup 2020 National Contest B Group, Problem J.
Translated by ChatGPT 5