HRJMP Editorial

PROBLEM LINK:

Practice
Contest

Author: Himanshu Raj
Editorialist: Chandan Boruah

DIFFICULTY:

SIMPLE

PREREQUISITES:

Brute Force, Maths.

PROBLEM:

Given a 2D array, print the maximum value of the length of jump to be chosen such that it is possible to visit few preselected positions. The direction of movement is allowed in both directions.

QUICK EXPLANATION:

The solution would be the greatest common divisor of given positions, which are selected to be visited. Then movement to each of them is possible.

NOTE:

The statement had a bug, in the explanation part.

SOLUTIONS:

Setter's Solution
from math import gcd
def gcd1(a,n):
	if(n==1):
		return a[0]
	else:
		f=a[0]
		for i in range(1,n):
			f=gcd(f,a[i])
		return f
n,x=map(int, input().split())
l=list(map(int, input().split()))
#print(n)
#print(n,x,l)
l.sort()
f=[]
for i in range(n):
	f.append(abs(l[i]-x))
print(gcd1(f,n))