Segment and Squares
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
In a rectangular coordinate system, you are given a square grid composed of (N^2) squares, each with sides parallel to the coordinate axes. Each square (S_ij) ((i, j = {1, ..., N})) has vertices at the coordinates ((K i - K, K j - K)), ((K i - K, K j)), ((K i, K j - K)), and ((K i, K j)).
A line segment is drawn from a point on the left boundary of the grid ((0, W)) to a point on the right boundary ((K N, E)). Your task is to determine how many of these grid squares have at least one point in common with this segment.
Input
The input consists of integers (N), (W), (E), and (K), separated by spaces, where (1 N, K 10^2000) and (0 W, E K N).
Output
Output the number of squares that intersect with the segment at least at one point.
Examples
Input #1
Answer #1
Submissions 17
Acceptance rate 18%