Segment and Squares#1133

Segment and Squares

1 segundo
64 megabytes
Fácil (≈1000)

In a rectangular coordinate system, there is a square grid composed of N^2 squares with sides parallel to the coordinate axes. Each square S_{ij} (i,j = 1,\ldots,N) has vertices at (K \cdot i - K,\ K \cdot j - K), (K \cdot i - K,\ K \cdot j), (K \cdot i,\ K \cdot j - K), and (K \cdot i,\ K \cdot j).

A line segment is drawn from point on the left boundary of the grid to point (K \cdot N, E) on the right boundary. Determine how many of the grid squares have at least one point in common with this segment.

Entrada

The input contains integers , , , separated by spaces, where 1 \leq N, K \leq 10^{2000} and 0 \leq W, E \leq K \cdot N.

Salida

Print the number of squares that intersect with the segment at least at one point.

Ejemplos

Ejemplo 1

Loading
Loading