The following question was asked in VK Cup Wild Card Round 1 Contest organised by codeforces. My code gives Time limit Exceeded error...Please help me out to optimise my solution. Here is the problem: There are n points on a straight line, and the ith point among them is located at Xi. All these coordinates are distinct. Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal. Also it is given that the position Xi of ith point lies between 10^9 to 10^9. Here is the link to my code: http://codeforces.com/contest/926/submission/36411390 The link to the original question is: asked 19 Mar '18, 21:15
converted to question 19 Mar '18, 22:15

When i solved this problem i come up with the same approach and you know what it got accepted in #234ms (In GNU C++ 14 Lang with gcd recursive version and with integer types ) Key Points for code optimization are:
answered 19 Mar '18, 23:29
