#P11214. Swallowed Diagonals in N-Dimensional Space
Swallowed Diagonals in N-Dimensional Space
Swallowed Diagonals in N-Dimensional Space
Given an -dimensional space, where the size of the \text{-th} dimension is . Each position is represented by coordinates $$(x_1, x_2, \dots, x_n)$$ with . There is a black hole at position $$(a_1,a_2,\dots,a_n)$$. A position $$(b_1,b_2,\dots,b_n)$$ is on the same diagonal as the black hole if and only if there exists an integer such that for every ,
All positions on the same diagonal (including the black hole itself) will be swallowed. Compute the number of positions swallowed modulo .
inputFormat
The input consists of three lines:
- The first line contains an integer , the number of dimensions.
- The second line contains integers , representing the size of each dimension.
- The third line contains integers , representing the coordinates of the black hole.
outputFormat
Output a single integer, the number of positions swallowed by the black hole modulo .
sample
1
5
3
5