Given two points A and B on the X-Y plane, output the number of the lattice points on the segment AB. Note that A and B are also lattice point. Those who are confused with the definition of lattice point, lattice points are those points which have both x and y co-ordinate as integer.
For example, for A (3, 3) and B (-1, -1) the output is 5. The points are: (-1, -1), (0, 0), (1, 1), (2, 2) and (3, 3).
Input
Input starts with an integer T (≤ 125), denoting the number of test cases.
Each case contains four integers, Ax, Ay, Bx and By. Each of them will be fit into a 32 bit signed integer.
Output
For each test case, print the case number and the number of lattice points between AB.
Sample Input
2
3 3 -1 -1
0 0 5 2
Sample Output
Case 1: 5
Case 2: 2
include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int t;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
scanf("%d",&t);
int w=0;
while(t--)
{w++;
ll a,b,c,d;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
printf("Case %d: %lld\n",w,gcd(abs(d-b),abs(c-a))+1);
}
return 0;
}