title: Logical Explanation to the below c/c++ solution
body: <p>Can someone please explain to me why is GCD used in the following Solution: </p>
  
  <p><a href="http://www.codechef.com/viewsolution/2849602" rel="nofollow noreferrer">http://www.codechef.com/viewsolution/2849602</a> (for c)</p>
  
  <p><a href="http://www.codechef.com/viewsolution/2849324" rel="nofollow noreferrer">http://www.codechef.com/viewsolution/2849324</a> (for c++)</p>
  
  <p>for the question: <a href="http://www.codechef.com/ACMKAN13/problems/LINEPROB" rel="nofollow noreferrer">http://www.codechef.com/ACMKAN13/problems/LINEPROB</a></p>
  
  <p>A Sniper is standing at the point (x1, y1) on the 2D XY Plane. He shoots from his position towards the point (x2, y2). You may assume that all points are integers.</p>
  
  <p>Consider the 2D grid formed by integer points on the XY Plane. The position of the Sniper and the Target are lattice points in this grid. The bullet shot by the Sniper will follow a straight line trajectory from (x1, y1) to (x2, y2). The bullet goes no further than (x2, y2).</p>
  
  <p>Consider the trajectory of the bullet when the Sniper is standing at (1, 1) and the Target lies at (4, 3).</p>
  
  <p><img src="https://i.stack.imgur.com/Eq2kT.png" alt="enter image description here"></p>
  
  <p>Notice how the trajectory of the bullet touches 4 cells. A cell is considered touched by the trajectory if and only if the bullet will enter the cell. How many cells are touched by the trajectory of the bullet?</p>
  
  <p>￼
  Input</p>
  
  <p>The first line contains a single integer T, the number of test cases. Each of the following T lines contain one test case each. Each test case contains 4 integers x1, y1, x2 and y2. The integers are separated by single space characters.
  Output</p>
  
  <p>For each test case, output a single line, containing the number of cells touched by the trajectory of the bullet shot from (x1, y1) to (x2, y2). Remember that a cell is considered touched by the trejectory if and only if the bullet enters the cell - only touching a side is not enough.
  Constraints</p>
  
  <p>0 &lt; T &lt; 10100
  0 ≤ x1, y1, x2, y2 ≤ 1000000000</p>
  
  <p>Sample Input</p>
  
  <p>3
  0 0 3 2
  0 0 2 2
  0 0 1 0</p>
  
  <p>Sample Output</p>
  
  <p>4
  2
  0</p>