DWITE Online Computer Programming Contest

Integers along a line

December 2010
Problem 1

When talking about points on the Cartesian plane, most people tend to deal only with points with integer coordinates (i.e. points whose x- and y-coordinates are integers). Given a line segment with integer coordinates, you are curious about how many points on the line segment (other than the endpoints) have integer coordinates.

The input file DATA1.txt will contain 5 lines, where each line has 4 integers −1000 ≤ A, B, X, Y ≤ 1000, such that (A, B) and (X,Y) describe the two endpoints of the line segment.

The output file OUT1.txt will contain 5 lines, with each line containing the number of points along the line (excluding the endpoints) that fall on integer coordinates.

Sample Input (first 2 shown):
0 0 2 2
-1 -2 1 1
Sample Output (first 2 shown):
1
0