atcoder#CODEFESTIVAL2017QUALCE. Cubes
Cubes
Score : points
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 .
3 4 5 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.
1 2 3 0
4
There are four blocks that are penetrated by the wire, and only these blocks satisfy the condition.
3 5 7 100
105
All blocks satisfy the condition.
3 123456781 1000000000 100
444124403
1234 12345 1234567 5
150673016
999999997 999999999 1000000000 50000
8402143