#codefestival2017qualce. [code_festival_2017_qualc_e]Cubes
[code_festival_2017_qualc_e]Cubes
Problem Statement
We constructed a rectangular parallelepiped of dimensions built of cubic blocks of side . Then, we placed the parallelepiped in -space as follows:
- For every triple (), there exists a block that has a diagonal connecting the points and . All sides of the block are parallel to a coordinate axis.
For each triple , we will call the above block as block .
For two blocks and , we will define the distance between them as max.
We have passed a wire with a negligible thickness through a segment connecting the points and . How many blocks satisfy the following condition? Find the count modulo .
- There exists a block such that the wire passes inside the block (not just boundary) and the distance between the blocks and is at most .
Constraints
- Any two of the three integers and are coprime.
Input
Input is given from Standard Input in the following format:
Output
Print the number of the blocks that satisfy the condition, modulo .
Sample Input 1
3 4 5 1
Sample Output 1
54
The figure below shows the parallelepiped, sliced into five layers by planes parallel to -plane. Here, the layer in the region is called layer .
The blocks painted black are penetrated by the wire, and satisfy the condition. The other blocks that satisfy the condition are painted yellow.
There are blocks that are painted black or yellow.
Sample Input 2
1 2 3 0
Sample Output 2
4
There are four blocks that are penetrated by the wire, and only these blocks satisfy the condition.
Sample Input 3
3 5 7 100
Sample Output 3
105
All blocks satisfy the condition.
Sample Input 4
3 123456781 1000000000 100
Sample Output 4
444124403
Sample Input 5
1234 12345 1234567 5
Sample Output 5
150673016
Sample Input 6
999999997 999999999 1000000000 50000
Sample Output 6
8402143