P27406 [AtCoder] Graph Paper and Line Segment
提高+
题目描述

Problem Description

Takahashi decided to draw a line segment on graph paper.

Starting from a certain grid cell, the cell reached by moving $x$ cells to the right and $y$ cells up is called cell $(x, y)$.

When drawing a line segment connecting the bottom-left point of cell $(A, B)$ and the bottom-left point of cell $(C, D)$, find the number of cells that the line segment crosses.

Here, when the line segment passes through the interior (excluding the boundaries) of a cell, it is said that the line segment crosses that cell.

Input Format

The input is given from the standard input in the following format:

$A$ $B$ $C$ $D$

Output Format

Output the number of cells that the line segment crosses.

Sample Input and Output

Sample Input #1

1 1 3 4

Sample Output #1

4

Sample Input #2

2 3 10 7

Sample Output #2

8

Notes/Hints

Constraints

  • $1 \leq A, B, C, D \leq 10^9$
  • At least one of $A \neq C$ or $B \neq D$ holds.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 1 3 4
样例输出
4