Problem:


Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999



Sample input:
3 3
1 7 11


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions
import numpy as np

tmp=input()
n = int(tmp.split(" ")[0])
X = int(tmp.split(" ")[1])
tmp=input()
i=int(0)
x=[]
for i in range(n):
    x.append(int(tmp.split(" ")[i]))
x.append(X)
x.sort()

x=np.array(x)

y=x[1:]-x[:-1]

y.sort()
y=list(set(y))
z=y[0]
m=len(y)
i=0
while i < m:
    z=fractions.gcd(z,y[i])
    i+=1

print(z)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
pos=list(map(int,input().split()))
pos2=[abs(p-x) for p in pos]
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
 
        return divisor_list
 
minpos= min(pos2)
divs=make_divisor_list(minpos)[::-1]
for j in divs:
    if all(x%j==0 for x in pos2):
        ans=j
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)


for i in range(min_distance,0,-1):
    Can_go_list=list(map(lambda z: 1 if z % i == 0 else 0,first_distance))

    if 0 not in Can_go_list:
        ans = i
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split() )
y = list(map(int,input().split()))
z = [0]*n

for i in range(n) :
   y[i] = abs(y[i]-x)

y.sort()

for i in range(n-1) :
   y[i] = y[i+1]-y[i]

for j in range(max(y),0,-1) :
   for i in range(n) :
      z[i] = y[i]%j

   if z == [0]*n :
      print(j)
      break

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
pos=list(map(int,input().split()))
pos2=[abs(p-x) for p in pos]
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
 
        return divisor_list
 
minpos= min(pos2)
divs=make_divisor_list(minpos)[::-1]
if divs[0]==1:ans=1
else:
  for j in divs:
    if all(x%j==0 for x in pos2):
        ans=j
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions
 
tmp=input()
n = int(tmp.split(" ")[0])
X = int(tmp.split(" ")[1])
tmp=input()
i=int(0)
x=[]
for i in range(n):
    x.append(int(tmp.split(" ")[i]))
x.append(X)
x.sort()
y=[]

i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()

ya=tuple(set(y))
m=len(ya)
z=y[0]
i=0
while i < m:
    z=fractions.gcd(z,ya[i])
    i+=1

print(z)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
cities = list(map(int, input().split()))
max_city = max(cities)
max_a=0
for i in cities:
    if abs(x-i) > max_a:
        max_a = abs(x-i)

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

def checker(cities, st, d):
    for city in cities:
        if((city-st)%d==0):
            continue
        else:
            return False
    return True

ans = 1
for cand in range(max_a, 0, -1):
    st = x
    while (True):
        if st-cand > 0:
            st -= cand
        else:
            break
    if(checker(cities, st, cand)):
        ans = cand
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
pos=list(map(int,input().split()))
pos2=[abs(p-x) for p in pos]
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

maxpos= max(pos2)
divs=make_divisor_list(maxpos)[::-1]
for j in divs:
    if all(x%j==0 for x in pos2):
        ans=j
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])

min = min(Points)
max = max(Points)

ran = max - min
interval = ran
end = False
Failed = False

for i in range(interval):
    Failed = False

    for p in Points:
        if (p - min) % interval != 0:
            Failed = True
            break

    if(not Failed):
        print(interval)
        exit()
    interval -= 1

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	M=min(LL)
	while any([l%M!=0 for l in LL]):
		M=M-1
	print(M)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
cities = list(map(int, input().split()))
max_city = max(cities)
max_a=0
for i in cities:
    if abs(x-i) > max_a:
        max_a = abs(x-i)

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

def checker(cities, st, d):
    for city in cities:
        if (city-st == 0):
            continue
        if (is_integer_num((city-st)/d)):
            continue
        else:
            return False
    return True

ans = 1
for cand in range(max_a, 0, -1):
    st = x
    while (True):
        if st-cand > 0:
            st -= cand
        else:
            break
    if(checker(cities, st, cand)):
        ans = cand
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions
 
tmp=input()
n = int(tmp.split(" ")[0])
X = int(tmp.split(" ")[1])
tmp=input()
i=int(0)
x=[]
for i in range(n):
    x.append(int(tmp.split(" ")[i]))
x.append(X)
x.sort()
y=[]

i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()

z=y[0]
i=0
while i < n:
    z=fractions.gcd(z,y[i])
    i+=1

print(z)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
  if(t == 1):
    flg = True
    break
if(flg):
  print(1)
else:
  k = d[0]
  j = 2
  while True:
    s = int(k/j)
    if(k % j == 0):
      d.append(s)
    if(s < 1):
      break
    j += 1

  d.sort()
  l = len(d)
  ans = 1
  for i in range(l):
    u = list(map(lambda x: x% d[l - 1 - i],e))
    if(u.count(0) == n):
      ans = d[l-1-i]
      break
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
list1 = list(map(int, input().split()))
num_city = list1[0]
start = list1[1]
city_list = list(map(int, input().split()))
flag = False
max_num = 1

list3 = []
if len(city_list) >= 2:
    for i in range(len(city_list) - 1):
        list3.append(abs(city_list[i + 1] - city_list[i]))
        if 1 in list3:
            break
else:
    list3.append(abs(city_list[0] - start))

maximum = min(list3)

for j in range(maximum):
    flag = False
    j2 = maximum - j
    amari = start % j2
    for k in range(len(city_list)):
        if (city_list[k] - amari) % j2 != 0:
            flag = True
            break
    if not flag:
        max_num = j2
        break

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
  if(t == 1):
    flg = True
    break
if(flg):
  print(1)
else:
  for i in range(1,int(d[0]/2)+1):
    if(d[0]%i==0):
      d.append(i)
  d.sort()
  l = len(d)
  ans = 1
  for i in range(l):
    u = list(map(lambda x: x% d[l - 1 - i],e))
    if(u.count(0) == n):
      ans = d[l-1-i]
      break
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
cities = map(int, input().split())
sorted_cities = sorted(cities)
max_city = sorted_cities[-1]
max_a=0
for i in sorted_cities:
    if abs(x-i) > max_a:
        max_a = abs(x-i)

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

def checker(cities, st, d):
    for city in cities:
        if (city-st == 0):
            continue
        if (is_integer_num((city-st)/d)):
            continue
        else:
            return False
    return True

ans = 1
for cand in range(max_a, 0, -1):
    st = x
    while (True):
        if st-cand > 0:
            st -= cand
        else:
            break
    if(checker(sorted_cities, st, cand)):
        ans = cand
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
list1 = list(map(int, input().split()))
num_city = list1[0]
start = list1[1]
city_list = list(map(int, input().split()))
flag = False
max_num = 1

list3 = []
if len(city_list) >= 2:
    for i in range(len(city_list) - 1):
        list3.append(abs(city_list[i + 1] - city_list[i]))
else:
    list3.append(abs(city_list[0] - start))

maximum = min(list3)

for j in range(maximum):
    flag = False
    j2 = maximum - j
    amari = start % j2
    for k in range(len(city_list)):
        if (city_list[k] - amari) % j2 != 0:
            flag = True
            break
    if not flag:
        max_num = j2
        break

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
def kou(a,b):
    while (a != 0):
        if a < b:
            k = a
            a = b
            b = k
        a = a % b
    return(b)

def main():    
    N,X = map(int,input().split())
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    while len(x) > 1:
#        print(x[0],x[1])
        y = kou(x[0],x[1])
        x.pop(0)
        x.pop(0)
        x.insert(0,y)
#        print(x)
    print(x[0])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

if n==1:
    print(abs(x-l[0]))
else:
    l.append(x)
    minimum=min(l)
    maximum=max(l)
    delta=maximum-minimum
    if delta==1:
        print(1)
    else:
        kouho=make_divisor_list(delta)
        ans=1
        for num in kouho:
            signal=1
            j=0
            while(j<n):
                if (l[j]-minimum)%num!=0:
                    signal=0
                    break
                else:
                    j+=1
            if signal==1:
                ans=num
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=list(set([abs(inputcities[i]-X) for i in range(N)]))
N=len(cities)
count=0
flag=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
  if flag==1:
    break

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=list(set([abs(inputcities[i]-X) for i in range(N)]))
N=len(cities)
count=0
flag=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if sum(cities)%j==0:
      if cities[i]%j==0:
        count+=1
      else:
        count=0
        break
      if count==N:
        print(j)
        flag=1
        break
    else:
      break
  if flag==1:
    break

Submission status: Time Limit Exceeded

Solution code:
n, x = tuple(map(int, input().split()))
points = [int(x) for x in input().split()]
points.append(x)
points.sort()

ds = [points[i + 1] - points[i] for i in range(len(points) - 1)]
for m in range(min(ds), 0, -1):
    if all([x % m == 0 for x in ds]):
        print(m)
        break

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split(" "))

xlist = map(int, input().split(" "))

x_dst = [xi - x for xi in xlist]


max_temp = abs(x_dst[0])
for d in x_dst:
    max_c = 1
    for i in range(max_temp):
        if abs(d) % (i+1) == 0:
            max_c = i+1
    if max_c < max_temp:
        max_temp = max_c
print(max_temp)

Submission status: Time Limit Exceeded

Solution code:
list1 = list(map(int, input().split()))
num_city = list1[0]
start = list1[1]
city_list = list(map(int, input().split()))
flag = False
max_num = 1
maximum = max(abs(max(city_list) - start), abs(start - min(city_list)))

for j in range(maximum):
    flag = False
    j2 = maximum - j
    amari = start % j2
    for k in range(len(city_list)):
        if (city_list[k] - amari) % j2 != 0:
            flag = True
            break
    if not flag:
        max_num = j2
        break

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
import math

def count_factor(factor, factors):
    count = 0
#    print("factor: " + str(factor))
#    print(factors)

    for f in factors:
        if f == factor:
            count += 1

    return count

def divide_to_prime_factors(num):
    factor = 1
    factors = []

    while factor <= math.sqrt(num):
        if num % factor == 0:
            factors.append(factor)
            if factor * factor != num:
                factors.append(int(num / factor))

        factor += 1

    return factors

n_and_x = input().split(" ")
city_num = int(n_and_x[0])
start = int(n_and_x[1])

city_places = [int(n) for n in input().split(" ")]

city_distances = []
for place in city_places:
    city_distances.append(abs(place - start))

dist_factors = []
for dist in city_distances:
    dist_factors.extend(divide_to_prime_factors(dist))
#print(dist_factors)

step = 1
for factor in dist_factors:
    if factor > step:
        fact_count = count_factor(factor, dist_factors)
#        print(fact_count)
        if fact_count == city_num:
            step = factor

#step = int(max(city_distances) / 2)

#can_travel = False
#while can_travel == False:
#    can_travel = True
#    for city in city_places:
#        if abs(city - start) % step != 0:
#           can_travel = False
#    if can_travel == False:
#        step -= 1

print(step)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
count=0
flag=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if sum(cities)%j==0:
      if cities[i]%j==0:
        count+=1
      else:
        count=0
        break
      if count==N:
        print(j)
        flag=1
        break
    else:
      break
  if flag==1:
    break

Submission status: Time Limit Exceeded

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =1
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2<mimN+1:
            flag=0
            for number in list3:
                if number%index2 !=0:
                    flag =1
            if flag ==0:
                ans = index2
            index2+=1
            
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import copy
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
limit=max(abs(x[0]-X),abs(x[len(x)-1]-X))
x_ans1=[]
x_ans2=[]
x_ansnum=[]
for i in range(1,limit+1):
    for j in range(1,limit+1):
        x_ans2.append(X+i*j)
        x_ans2.append(X-i*j)
    x_ans1.append(copy.copy(x_ans2))
    x_ans2.clear()
for k in range(limit):
    if len(set(x)&set(x_ans1[k]))==len(x):
        x_ansnum.append(k)
print(max(x_ansnum)+1)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

if n==1:
    print(abs(x-l[0]))
else:
    l.append(x)
    minimum=min(l)
    maximum=max(l)
    delta=maximum-minimum
    if delta==1:
        print(1)
    else:
        kouho=make_divisor_list(delta)
        ans=1
        for num in kouho:
            signal=1
            for j in range(n):
                if (l[j]-minimum)%num!=0:
                    signal=0
            if signal==1:
                ans=num
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
count=0
flag=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
  if flag==1:
    break

Submission status: Time Limit Exceeded

Solution code:
N,X=(int(i) for i in input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
b=[]
for i in range(N):
    c=x[i+1]-x[i]
    b.append(c)

d=max(b)
for j in range(d):
    zako = map(lambda x: x%(d-j), b)
    if list(zako).count(0) == N:
        ans=(d-j)
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
xn = list(map(int, input().split()))

xn = [abs(i - x) for i in xn]

if n == 1 :
    print(xn[0])
else:
    for i in range(min(xn), 0, -1):
        if not any([j % i for j in xn]):
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
def check_ans(temp_sub,ans):
    count = 0
    for i in temp_sub:
        if i%ans ==0:
            count += 1
        else:
            pass
    # print(count)
    if count == len(temp_sub):
        return False
    else:
        return True

N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    x.sort()
    X_index = serch_index(X, x)
    x.insert(X_index+1, X)
    # print(x)
    temp_sub = []
    for i in range(N):
        temp_sub.append(x[i+1]-x[i])

    ans = abs(min(temp_sub))
    judge = True
    while judge:
       judge = check_ans(temp_sub, ans)
       if judge:
            ans -=2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    m = np.min(x)
    for n in range(m, 0, -1):
        if x[x%n != 0].size == 0:
            print(n)
            return 0

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =1
if len(list3) ==1:
    print(mimN)
else:
    while index2<mimN+1:
        flag=0
        for number in list3:
            if number%index2 !=0:
                flag =1
        if flag ==0:
            ans = index2
        index2+=1
        
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
xlist =[X]
xlist.extend(list(map(int, input().split())))
dlist =[]
for i in range(N):
    dlist.append(xlist[i+1]-xlist[i])
D = 1
for i in range(2, abs(min(dlist))+ 1):
    for d in dlist:
        if d % i != 0:
            break
    else:
        D = i
print(D)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

N, X = map(int, input().split())

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

# li = [i for i in li if i]

if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))

for i in range(N):
    x[i] = abs(x[i] - X)
    if x[i] == 0:
        x[i] = 10000000000
m = min(x)

flg = True
for i in range(m,0,-1):
    for j in range(N):
        if x[j] % i != 0:
            flg = False
            break

    if flg == True:
        print(i)
        exit()
    else:
        flg = True

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	M=min(LL)
	while any([l%M!=0 for l in LL]):
		M=M-1
	print(M)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    a.sort()
    box = [a[i+1]-a[i] for i in range(n-1)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)

Submission status: Time Limit Exceeded

Solution code:
n,X = map(int,input().split())
x =list(map(int,input().split()))
x.append(X)
x.sort()
a = []
for i in range(n):
  a.append(x[i+1]-x[i])
  
g = []
h = min(a)
for i in range(h,0,-1):
  if h%i == 0:
    g.append(i)
    
gcd = 1
for i in g:
  if all(a[j]%i == 0 for j in range(n)) :
    gcd = i
    break
    
    
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

N, X = map(int, input().split())

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

li = [i for i in li if i]

if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    box = [a[i+1]-a[i] for i in range(n-1)]
    box.sort()
    for i in range(1,box[0]+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)

Submission status: Time Limit Exceeded

Solution code:
n,X = map(int,input().split())
x =list(map(int,input().split()))
x.append(X)
x.sort()
a = []
for i in range(n):
  a.append(x[i+1]-x[i])
  
g = []
h = min(a)
for i in range(1,h+1):
  if h%i == 0:
    g.append(i)
    
gcd = []
for i in g:
  if all(a[j]%i == 0 for j in range(n)):
    gcd.append(i)
    
print(max(gcd))

Submission status: Time Limit Exceeded

Solution code:
N, X = [int(x) for x in input().split(' ')]

city = [abs(int(x) - X) for x in input().split(' ')]
max_fact = city[0]

for x in city:
    while x!=0:
        if x > max_fact:
            x -= max_fact
        elif x == max_fact:
            break
        else:
            tmp = max_fact
            max_fact = x
            x = tmp
    if max_fact==1:
        break

print(max_fact)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split() )
y = list(map(int,input().split()))
z = [0]*n

for i in range(n) :
   y[i] = abs(y[i]-x)

y.sort()

for i in range(n-1) :
   y[i] = y[i+1]-y[i]

for j in range(y[n-1],1,-1) :
   for i in range(n) :
      z[i] = y[i]%j

   if z == [0]*n :
      print(j)
      break

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8
N, X = map(int, input().split())
dx = list(map(lambda x: x - X, map(int, input().split())))

dx_nearest = 10**9
for dxi in dx:
    if (2 *(dxi > 0) - 1) * dxi < dx_nearest: dx_nearest = (2 *(dxi > 0) - 1) * dxi

for D in range(dx_nearest + 1)[::-1]:
    for dxi in dx:
        if dxi % D > 0: break
        else: continue
    else:
        print(D)
        break
else: print("oops")

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

while minimum != 1:
  flag = 0
  for d in dist_list:
    if d % minimum != 0:
      flag = 1
  if flag == 0:
    break
  else:
    minimum -= 1

print(minimum)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int,input().split())
xl = list(map(int,input().split()))

xl.append(x)
xl.sort()
sa = []
onesam = 2000000000
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if one_sa % onesam == 0:
        continue
    if onesam > one_sa:
        onesam = one_sa
        sa.append(one_sa)
        
    
sa.sort()
samin = min(sa)

flag = 0
while flag == 0:
    amari = 0
    for i in sa:
        amari += i % samin
        if amari != 0:
            break
            
    if amari == 0:
        flag = 1
        break
    else:
        for j in range(1,samin+1):
            if samin % j == 0:
                samin = samin // j
                break
print(samin)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split() )
y = list(map(int,input().split()))
z = [0]*n

for i in range(n) :
   y[i] = abs(y[i]-x)

y.sort()

for j in range(y[n-1],1,-1) :
   for i in range(n) :
      z[i] = y[i]%j

   if z == [0]*n :
      print(j)
      break

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

n,x = map(int,input().split())
y = list(map(int,input().split()))
y.append(x)
y.sort()

dif = []
for i in range(n):
    dif.append(y[i+1]-y[i])

if len(dif) != 1:
    for i in range(len(dif)-1):
        ad = gcd(dif[0],dif[1])
        dif.append(ad)
        dif.pop(0)
        dif.pop(0)
    print(dif[0])
else:
    print(dif[0])

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int,input().split())
xl = list(map(int,input().split()))

xl.append(x)
xl.sort()
sa = []
for i in range(len(xl)-1):
    sa.append(xl[i+1] - xl[i])
sa.sort()
samin = min(sa)

flag = 0
while flag == 0:
    amari = 0
    for i in sa:
        amari += i % samin
        if amari != 0:
            break
            
    if amari == 0:
        flag = 1
        break
    else:
        for j in range(1,samin+1):
            if samin % j == 0:
                samin = samin // j
                break
print(samin)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = np.array(x)
x = x - X

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

xabs= np.abs(x)

a = x[np.argmax(xabs)]
b = x[np.argmin(xabs)]

y = []
for a in x:
    for b in x:
        y.append(abs(gcd(a,b)))
print(np.min(y))

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int,input().split())
xl = list(map(int,input().split()))

xl.append(x)
xl.sort()
sa = []
for i in range(len(xl)-1):
    sa.append(xl[i+1] - xl[i])
    
samin = min(sa)

flag = 0
while flag == 0:
    amari = 0
    for i in sa:
        amari += i % samin
        break
    if amari == 0:
        flag =1
        break
    else:
        for j in range(1,samin+1):
            if samin % j == 0:
                samin = samin // j
                break
print(samin)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
x=sorted(map(lambda x:int(x)-X if int(x)-X>0 else -(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int,input().split())
xl = list(map(int,input().split()))

xl.append(x)
xl.sort()
sa = []
for i in range(len(xl)-1):
    sa.append(xl[i+1] - xl[i])
    
samin = min(sa)

flag = 0
while flag == 0:
    amari = 0
    for i in sa:
        amari += i % samin
    if amari == 0:
        flag =1
        break
    else:
        for j in range(1,samin+1):
            if samin % j == 0:
                samin = samin // j
                break
print(samin)