Geometry
Geometry-03
Geometry-04
Geometry-05
~/algor $ cat problems/kesmadagi-butun-nuqtalar
Lattice points on a segment
Easy
1000 ms
128 MB
27%
A segment $AB$ with endpoints $A(x_{1}; y_{1})$ and $B(x_{2}; y_{2})$ is given. How many points with both coordinates integer lie on the segment (including its endpoints)? Points $A$ and $B$ may coincide.
Input
One line with four integers: $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$.
Output
One integer — the number of lattice points.
Note
$-10^{9} \le x_{1}, y_{1}, x_{2}, y_{2} \le 10^{9}$
Examples
Input #1
1 1 7 4
Output #1
4
Input #2
0 0 3 5
Output #2
2