Please enter your email address or userHandle.
Given two points p (x1, y1) and q (x2, y2), Calculate the number of integral points lying on the line joining them.
Note: You are given the 4 points x1, y1, x2, y2 as Input.
x1 = 2, y1 = 2, x2 = 5, y2 = 5
There are only 2 integral points on the
line joining (2,2) and (5,5).
The points are (3,3) and (4,4).
x1 = 1, y1 = 9, x2 = 8, y2 = 16
There are 6 integral points on the
line joining (1,9) and (8,16).
You don't need to read input or print anything. Your task is to complete the function countIntegralPoints() which takes 4 Integers x1,y1,x2 and y2 as input and returns the answer.
Expected Time Complexity: O(log(max(x1,x2,y1,y2)))
Expected Auxiliary Space: O(1)
1 <= x1,x2,y1,y2 <= 108
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.