#P6452. Guarded Rectangle
Guarded Rectangle
Guarded Rectangle
In a Cartesian coordinate system, there is a rectangle with two opposite corner points at \( (1,-A) \) and \( (L,B) \). The rectangle contains \( L \times (A+B+1) \) grid points (all points with integral coordinates).
There are two guards located at \( (0,-A) \) and \( (0,B) \) respectively. Each guard looks toward the rectangle. A guard can see a grid point \( (x,y) \) if and only if the ray from the guard to \( (x,y) \) is not blocked by any other grid point within the rectangle. In other words, for a guard positioned at \( (0,Y) \) and a grid point \( (x,y) \), let the vector be \( (x, y-Y) \). The guard can see \( (x,y) \) if and only if \( \gcd(x,|y-Y|)=1 \) (here \( \gcd(a,0)=a \) for any positive integer \( a \)).
Based on the above, each point in the rectangle is classified as follows:
- Very Safe: visible by both guards.
- Safe: visible by exactly one guard.
- Dangerous: visible by neither guard.
Given \( A \), \( B \), and \( L \), count the number of very safe points, safe points, and dangerous points respectively.
inputFormat
The input consists of three integers \( A \), \( B \), and \( L \) separated by spaces, where \( A, B \ge 0 \) and \( L \ge 1 \). The rectangle covers all points \( (x,y) \) with integer coordinates satisfying \( 1 \le x \le L \) and \( -A \le y \le B \).
outputFormat
Output three integers separated by spaces: the number of very safe points, safe points, and dangerous points, in that order.
sample
1 1 2
4 0 2