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: Accepted

Solution code:
n,x=map(int,input().split())
xl=list(map(int,input().split()))
for i in range(n):
    xl[i]=abs(xl[i]-x)
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

while len(xl)>1:
    xl[0]=gcd(xl[0],xl[1])
    del xl[1]
    
print(xl[0])

Submission status: Accepted

Solution code:
def solve(diff_list):
    max_gcd = diff_list[0]
    for key in range(1, len(diff_list)):
        max_gcd = gcd(max_gcd, diff_list[key])
    return max_gcd

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

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))

    diff_list = []
    for i in x_list:
        diff_list.append(abs(i - x))

    ans = solve(diff_list)
    print(ans)

main()

Submission status: Accepted

Solution code:
n, init = map(int,input().split())
x = list(map(lambda x: abs(int(x)-init), input().split()))
g = x[0]
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
for i in range(1,n):
    g = gcd(g,x[i])
print(g)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
L = list(map(int, input().split()))
L.append(X)
L.sort()
cand = []
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

for i in range(N):
    cand.append(abs(L[i] - L[i+1]))

for i, can in enumerate(cand):
    if i == 0:
        tmp = can
        continue
    tmp = gcd(tmp, can)
print(tmp)

Submission status: Accepted

Solution code:
from functools import reduce

n, x = [int(i) for i in input().split(" ")]
xs = [int(i) for i in input().split(" ")]

xs = list(map(lambda k: abs(k - x), xs))

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

print(reduce(gcd, xs))

Submission status: Accepted

Solution code:
import fractions
n, x = map(int, input().split())
xi = list(map(int, input().split()))
xi.sort()

L = []
for i in range(n):
    L.append(abs(x - xi[i]))
if 0 in L:
    L.remove(0)

for i in range(len(L) - 1):
    L[i+1] = fractions.gcd(L[i], L[i+1])
print(L[len(L) - 1])

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_c

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)


def main():
    N, X = map(int, input().split())

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

    ans = abs(X - xl[0])
    for i in range(1, len(xl)):
        ans = gcd(max(ans, abs(X - xl[i])), min(ans, abs(X - xl[i])))

    print(ans)


main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
y = [x] + list(map(int, input().split()))
y.sort()

def g(a, b):
    while b != 0:
        a, b = b, a%b
    return a

for i in range(n):
    y[i] = y[i+1] - y[i]
y.pop()
for i in range(n-1):
    y[i+1] = g(y[i+1], y[i])

print(y[-1])

Submission status: Accepted

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

def gcd(x, y):
    while (y != 0):
        x, y = y, x%y

    return x

ans = abs(l[0] - x)

for d in l[1:]:
    ans = gcd(ans, abs(d - x))

print(ans)

Submission status: Accepted

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

def gcd(x, y):
    while (y != 0):
        x, y = y, x%y

    return x

diff = []

for j in l:
    diff.append(abs(j - x))

ans = diff[0]

for d in diff[1:]:
    ans = gcd(ans, d)

print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
 
 
def main():
    n, y = map(int, input().split())
    xs = list(map(int, input().split()))
    res = abs(y - xs[0])
    for x in xs[1:]:
        res = gcd(res, abs(y - x))
    print(res)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions as f

n,x = list(map(int,input().split()))
if n == 1:
    skip = int(input())
    if x == skip:
        print(0)
    else:
        print(abs(x-skip))
else:
    skip = list(map(int,input().split()))
    skip.append(x)
    skip = sorted(skip)
    margin = list()
    for i in range(len(skip)-1):
        margin.append(skip[i+1]-skip[i])
    margin = sorted(margin)
    test = margin[0]
    for i in range(len(margin)):
        test = f.gcd(test,margin[i])
    print(test)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':




def gcd(big, small):
	if big < small:
		tmp = big
		big = small
		small = tmp

	if small == 0:
		return big
	else:
		return gcd(small, big % small)


if __name__ == '__main__':
	N, X = map(int, input().rstrip().split())
	x_s = list(map(int, input().rstrip().split())) + [X]
	x_s = sorted(x_s)

	sec_s = []
	for i in range(1, N+1):
		sec_s.append(x_s[i] - x_s[i-1])
	
	ans = sec_s[0]
	for sec in sec_s[1:]:
		ans = gcd(ans, sec)
	print(ans)

Submission status: Accepted

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

mx = abs(xlist[0] - x)
for _x in xlist[1:]:
  mx = gcd(max(abs(_x-x), mx), min(abs(_x-x), mx))
print(mx)

Submission status: Accepted

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

x.sort()

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 10**9

if N >= 2:
   for i in range(N-1):
       keepgcd = gcd(abs(X-x[i+1]),abs(X-x[i]))
       if maxgcd > keepgcd:
          maxgcd = keepgcd
   print(maxgcd)
else:
    print(max(x[0],X)-min(x[0],X))

Submission status: Accepted

Solution code:
from fractions import gcd
n,x = map(int,input().split())
l = list(map(int,input().split()))
ll = [abs(x-i) for i in l]
ans = ll[0]
for i in range(len(ll)):
    ans = gcd(ans,ll[i])
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = abs(L[i]-X)
L.sort()
L.reverse()
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)
def listgcd(L):
  p = L[0]
  for i in range(1,N):
    p = gcd(p,L[i])
  return p
if len(L) >= 2:
  print(listgcd(L))
else:
  print(L[0])

Submission status: Accepted

Solution code:
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

gcd = functools.reduce(fractions.gcd,diff)
print(abs(gcd))

Submission status: Accepted

Solution code:
values = raw_input()
n,x = int(values.split(" ")[0]), int(values.split(" ")[1])
cities = raw_input()
cities = [int(i) for i in cities.split(" ")]

cities = sorted(cities)

distances = []
for i in cities:
	distances.append(abs(i-x))
for i in range(1,len(cities)):
	distances.append(abs(cities[i]-cities[i-1]))

def hcd(a,b):
	while b!=0:
		t = b
		b = a % b
		a = t
	return a

m = distances[0]
for i in range(1,len(distances)):
	m = hcd(m, distances[i])
print(m)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.append(X)
x_list.sort()
diff_list = [x_list[i + 1] - x_list[i] for i in range(len(x_list) - 1)]
print(reduce(gcd, diff_list))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)

Submission status: Accepted

Solution code:
n,x = (int(i) for i in input().split())
listx=[int(i) for i in input().split()]
#print(n,x,listx)
listy=[abs(listx[i]-x) for i in range(n)]
listy.reverse()
#print(listy)

def gcd(y, x):
    if x == 0:
        return y
    else:
        return gcd(x, y % x) #再帰定義
if n==1:
  ans=listy[0]
else:
  if listy[1]==0:
    ans=listy[0]
  else:
    ans=gcd(listy[0],listy[1])
    if n > 2:
      for i in range(0,n-2):
        if listy[i+2]==0:
          ans=ans
        else:
          ans=gcd(ans,listy[i+2])
  
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
dif_x = [x[i + 1] - x[i] for i in range(len(x) - 1)]
n = max(dif_x)  # の約数だけ調べる
divisors = []
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
            divisors.append(n // i)
divisors.sort(reverse=True)
# print(divisors)
for i in divisors:
    frag = True
    for j in dif_x:
        if j % i == 0:
            continue
        else:
            frag = False
            break
    if frag:
        print(i)
        break

Submission status: Accepted

Solution code:
n,o = map(int, input().split())
X = list(map(int, input().split()))
X = [abs(x-o) for x in X]

def euclid(a, b):
    if a>b:
        tmp = a
        a = b
        b = tmp
    while a>0:
        c = b%a
        b = a
        a = c
    return b

def sub_gcd(X):
    Y = []
    P, Q = len(X)//2, len(X)%2
    for p in range(P):
        y = euclid(X[2*p], X[2*p+1])
        Y.append(y)
    if Q!=0:
        Y.append(X[-1])
    return Y

def gcd(X):
    Y = sub_gcd(X)
    while len(Y)>1:
        Y = sub_gcd(Y)
    return Y[0]

print(gcd(X))

Submission status: Accepted

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

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

dif=[]
for i in range(n):
    dif.append(abs(X[i]-x))

def gcd(a,b):
    a,b=max(a,b),min(a,b)
    if b>0:
        return gcd(b,a%b)
    else:
        return a

ans=dif[0]
for i in range(1,n):
    ans=gcd(ans,dif[i])

    
    
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n, x = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]
xlist.append(x)
xlist.sort()
distlist = []
for i in range(len(xlist) - 1):
    distlist.append(xlist[i+1] - xlist[i])

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd(distlist))

Submission status: Accepted

Solution code:
n,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
a=[]
for i in range(len(x)-1):
        a.append(x[i+1]-x[i])        

def gcd(m,n):
        while n:
                m,n = n,m%n
        return m

ans=a[0]
for j in a:
        if j%ans != 0:
                ans = gcd(j,ans)
print(ans)

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
  a, b = max(a, b), min(a, b)
  if b == 0:
    return a
  else:
    return gcd(b, a % b)


def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  
  ans = C[0]
  for i in range(1, len(C)):
    ans = gcd(ans, C[i])

  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  min_C = min(C)
  ans = 1
  for i in range(min_C, 1, -1):
    if min_C % i != 0:
      continue
    
    if all([c % i == 0 for c in C]):
      ans = i
      break
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,tmp1 = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.append(tmp1)
x.sort()
query = []
for i in range(n):
  query.append(x[i+1]-x[i])
print(gcd_list(query))

Submission status: Accepted

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
tmp = [abs(X-xx) for xx in x]
ans = tmp[0]
for i in range(1,N):
  ans = gcd(ans, tmp[i])
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)
if len(diffList) > 1:
    diffList.sort()
    gcdList = []
    for x in diffList[1:]:
        gcdList.append(gcd(diffList[0], x))
    gcdList.sort()
    print(gcdList[0])
else:
    print(diffList[0])

Submission status: Accepted

Solution code:
from functools import reduce


class Solver(object):
    def __init__(self):
        self.n, self.x = list(map(int, input().split(" ")))
        self.x_s = list(map(int, input().split(" ")))

    def solve(self):
        self.shifted = [abs(self.x - i) for i in self.x_s]
        print(Solver.gcd(self.shifted))

    @staticmethod
    def gcd(numbers):
        if len(numbers) < 1:
            raise ValueError
        if len(numbers) == 1:
            return numbers[0]
        return reduce(Solver.pair_gcd, numbers)

    @staticmethod
    def pair_gcd(a, b):
        """a = bq + r"""
        a, b = (max(a, b), min(a, b))
        if b == 0:
            return a
        else:
            r = a % b
            return Solver.pair_gcd(b, r)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Submission status: Accepted

Solution code:
from functools import reduce

n, s = map(int, input().split())
xl = [int(i) - s for i in input().split()]

def gcd_(a, b):
    while b:
        a, b = b, a%b
    return a
def gcd(*numbers):
    return reduce(gcd_, numbers)

print(abs(gcd(*xl)))

Submission status: Accepted

Solution code:
from functools import reduce

n, s = map(int, input().split())
xl = [abs(int(i) - s) for i in input().split()]

def gcd_(a, b):
    while b:
        a, b = b, a%b
    return a
def gcd(*numbers):
    return reduce(gcd_, numbers)

print(gcd(*xl))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,x = map(int, input().split())
    xs = list(map(int, input().split()))
    xs.append(x)
    xs.sort(reverse=True)
    dif = [0]*n
    front = xs[0]
    for i,num in enumerate(xs[1:]):
        dif[i] = front - num
        front = num
    min_dif = min(dif)
    div_min = [min_dif]
    for i in range(int(min_dif**0.5),1,-1):
        if min_dif%i == 0:
            div_min.append(i)
            div_min.append(min_dif//i)
    div_min.sort(reverse=True)
    for i in div_min:
        for j in dif[1:]:
            if j % i != 0:
                break
        else:
            print(i)
            exit()
    print(1)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# import math
from functools import reduce
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]

print( reduce(gcd, A) )

Submission status: Accepted

Solution code:
N, X = map(int,input().split())
x = list(map(int,input().split()))
tmp = []
for i in range(N):
  tmp.append(abs(x[i] - X))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
ans = tmp[0]
for t in tmp:
  if(t%ans != 0):
    ans = gcd(ans, t)
print(ans)

Submission status: Accepted

Solution code:
import fractions


def func(l):
    # r = fractions.gcd(l[0], l[1])
    for i in range(len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def func2(l):
    if len(l) == 1:
        return l[0]

    r = fractions.gcd(l[0], l[1])
    i = 2
    while i <= len(l) - 1:
        r = fractions.gcd(r, l[i])
        i += 1
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()

    # if n == 1:
    #     print(abs(xl[1] - xl[0]))
    #     return

    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func2(dl))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions


def func(l):
    r = fractions.gcd(l[0], l[1])    
    for i in range(1, len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    if n == 1:
      print(abs(xl[1] - xl[0]))
      return
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(x, y):
  while(y > 0):
    x, y = y, x % y
  return x
n, x = map(int, input().split())
city = list(map(int, input().split()))
dist = []
for i in range(n):
  dist.append(abs(city[i] - x))
g = dist[0]
for i in range(1, n):
  g = gcd(g, dist[i])
print(g)

Submission status: Accepted

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

subs = []
for i in range(N):
  subs.append(abs(x[i] - X))
ans = subs[0]
for sub in subs:
  if(sub%ans != 0):
    ans = gcd(ans, sub)
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
lst = list(map(int, input().split()))
 
lst.append(x)
lst.sort()
 
dif_lst = []
for i in range(len(lst)-1):
    dif = lst[i+1] - lst[i]
    dif_lst.append(lst[i+1] - lst[i])
dif_lst.sort()

lst = dif_lst
while True:
    dif_lst = [lst[0]]
    for i in range(len(lst)-1):
        dif = lst[i+1] - lst[i]
        if dif == 0:
            continue
        else:
            dif_lst.append(lst[i+1] - lst[i])
    dif_lst.sort()
    if dif_lst[0] == 1:
        print(1)
        break
    elif len(dif_lst) == 1:
        print(dif_lst[0])
        break
    lst = dif_lst

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)

from fractions import gcd

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

X = list(map(int,input().split()))
X = [abs(i-x) for i in X]
# print(X)

# def gcd(m,n):
#     mx = max(m,n)
#     mn = min(m,n)
#     tmp = mx%mn
#     if tmp == 0:
#         return mn
#     else:
#         return gcd(mn, tmp)

def gcd_list(data):
    # if len(data)==1:
    #     return data[0]
    # tmp = gcd(data[0], data[1])
    # if len(data)==2:
    #     return tmp
    # else:
    #     new_data = [tmp]+data[2:]
    #     return gcd_list(new_data)
    ret = data[0]
    for d in data[1:]:
        ret = gcd(ret, d)
    return ret
# print(gcd_list([2,4,8]))
print(gcd_list(X))

Submission status: Accepted

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

from fractions import gcd
ans = abs(x - li[0])
for y in li[1:]:
    ans = gcd(ans, abs(x - y))

print(ans)

Submission status: Accepted

Solution code:
import fractions

N, X = [int(n) for n in input().split()]
x = sorted([abs(int(n) - X) for n in input().split()])

if len(x) > 1:
  gcd = fractions.gcd(x[0], x[1])
  for i in x:
    gcd = fractions.gcd(gcd, i)
else:
  gcd = x[0]
print(gcd)

Submission status: Accepted

Solution code:
from fractions import gcd
n,x = map(int,input().split())
l = list(map(int,input().split()))
l = [abs(i-x) for i in l]
res = l[0]
for i in range(1,n):
    res = gcd(res,l[i])
print(res)

Submission status: Accepted

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

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
if n==1:
    ans=abs(x[0]-x0)
else:
    ans=gcd(abs(x[0]-x0),abs(x[1]-x0))
    for i in range(n):
        ans=gcd(ans,abs(x[i]-x0))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator, fractions
from bisect import *

N, x = map(int, input().split())
X = [int(x) for x in input().split()]

def f():
    X.sort()
    L = len(X)
    if L == 1:
        return abs(X[0] - x)
    
    i = bisect_left(X, x)
    
    d = [t - u for t,u in zip(X[1:], X[:-1])]
    s = None
    if i == 0:
        s = set(d)
        s.add(x[0] - x)
    elif i == len(X):
        s = set(d)
        s.add(x - X[-1])
    else:
        s = set(d[:i - 1])
        s.update(d[i+1:])
        s.update({x - X[i-1], X[i] - x})
    return reduce(fractions.gcd, s)

print(f())

Submission status: Accepted

Solution code:
# ABC 109
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]
def gcd(x, y):
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n
def db(x): 
    global debug
    if debug: print(x)
debug = False
N,X = getIntList()
x = getIntList()
dif = zeros(N)
for i in range(N-1):
    dif[i] = x[i+1] - x[i]
dif[N-1] = x[N-1] - X
db(dif)
cd = dif[N-1]
for i in range(N-1):
    cd = gcd(cd,dif[i])
cd = abs(cd)
print(cd)

Submission status: Accepted

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

sub_list = []
for i in range(N):
  sub_list.append(abs(x[i] - X))
ans = sub_list[0]
for i in range(N):
  if(sub_list[i]%ans != 0):
    ans = gcd(ans, sub_list[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, O = map(int, input().split())
X = list(map(int, input().split()))
X.append(O)
X.sort()
diff = [x-y for x, y in zip(X[1:], X[:-1])]
# print(diff)
for i in range(N-1):
    diff[i+1] = gcd(diff[i], diff[i+1])
print(diff[N-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while 0 < b:
        a, b = b, a % b
    return a


def main():
    na = list(map(int, input().split()))
    N, X = na[0], na[1]
    x = list(map(int, input().split()))

    y = list(map(lambda v: abs(v - X), x))

    a = reduce(gcd, y)

    print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

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

ans = None
for i in xi:
    distance = abs(i-x)
    if ans is None:
        ans = distance
    else:
        ans = gcd(ans, distance)
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
def yakusu(num):
    top = []
    bot = []
    for i in range(int(math.sqrt(num))):
        k = i+1
        if num%k == 0:
            top.append(num//k)
            bot.append(k)
    return top + bot[::-1]

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
start = x[0]
x = np.array(x[1:])
x -= start
# print(x)

for ans_pred in yakusu(x[0]):
    if ans_pred == 1:
        break
    flag = True
    for i in x:
        if i % ans_pred != 0:
            flag= False
            break
    if flag:
        break

print(ans_pred)

Submission status: Accepted

Solution code:
from fractions import gcd
n, x = map(int,input().split())
xi = list(map(int,input().split()))

for i, n in enumerate(xi):
    xi[i] = abs(xi[i]-x)
ans = xi[0]
for i in range(len(xi)):
    ans = gcd(ans, xi[i])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    if N == 1:
        ans = dx[0]
    else:
        ans = 10 ** 9
    for i in range(N - 1):
        nm = dx[i]
        dm = dx[i + 1]
        while True:
            mod = nm % dm
            if mod == 0:
                break
            nm = dm
            dm = mod
        ans = min(ans, dm)
    print(ans)


main()

Submission status: Accepted

Solution code:
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    if N == 1:
        ans = dx[0]
    else:
        ans = 10 ** 9
    for i in range(N - 1):
        nm = max(dx[i], dx[i + 1])
        dm = min(dx[i], dx[i + 1])
        while True:
            mod = nm % dm
            if mod == 0:
                break
            nm = dm
            dm = mod
        ans = min(ans, dm)
    print(ans)


main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
A = [int(i) for i in input().split()]
D = []

for i in range(n):
    D.append(abs(x - A[i]))
    
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

for i in range(n - 1):
    D[i + 1] = gcd(D[i], D[i + 1])
    
print(D[-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    n, x = map(int, input().split())
    xn = list(map(int, input().split()))
    di = [abs(xi - x) for xi in xn]
    res = di[0]
    for i in range(1, n):
        res = gcd(res, di[i])
    print(res)

def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

main()

Submission status: Accepted

Solution code:
import functools

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
n,x = map(int,input().split())
list_x = list(map(int,input().split()))

diff=[None]*n
for i in range(n):
  diff[i] = abs(list_x[i] - x)


ans = functools.reduce(gcd, diff)
  
print(ans)

Submission status: Accepted

Solution code:
import fractions

N,X = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
#d = [abs(X-i) for i in x if abs(X-i)!=0]
d = [abs(X-i) for i in x]

gcd = d[0]
i=1
while True:
    if i>=N:
        break
    gcd = fractions.gcd(gcd,d[i])
    i=i+1 

print(gcd)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
def main(n,x,lst):
    lst.append(x)
    lst.sort()
    ans = [0for i in range(n)]
    for i in range(n):
        ans[i] = lst[i+1]-lst[i]
    return reduce(gcd,ans,0)
n,x = map(int,input().split())
lst = list(map(int,input().split()))
print(main(n,x,lst))

Submission status: Accepted

Solution code:
from functools import reduce
N, X = [int(a) for a in input().strip().split()]
x = [int(a) for a in input().split()]
y = [a - X for a in x]
y.sort()

if len(y) == 1:
    print(abs(y[0]))
    exit()

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

ydiff = []
for i in range(0, len(y)-1):
    if y[i+1] * y[i] < 0:
        ydiff.append(abs(y[i]))
        ydiff.append(abs(y[i+1]))
    else:
        ydiff.append(y[i+1] - y[i])
y = list(set(y)) 

if len(ydiff) == 1:
    ydiff.append(ydiff[0])

print(reduce(gcd, ydiff))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

N, X = list(map(int, input().split()))
x = [i-X for i in list(map(int, input().split()))]

def func(nums):
    return reduce(fractions.gcd, nums)

print(abs(func(x)))

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
N=N+1
lens=[abs(x[i]-x[i+1]) for i in range(0,N-1)]
lens=list(set(lens))

def GCD(a,b):
    if(b==0):
        return a
    else:
        return GCD(b,a%b)


x=lens[0]
for i in range(1,len(lens)):
    x=GCD(x,lens[i])

print(x)

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = abs(X-src[0])
for x in src[1:]:
    g = gcd(g,abs(X-x))
print(g)

Submission status: Accepted

Solution code:
def gcd(a,b):

    c=max(a,b)
    d=min(a,b)
    while True:
        if c%d==0:
            break
        else:
            temp=c
            c=d
            d=temp%d
    return d

def two_gcd(x):
    if len(x)==2:
        return gcd(x[0],x[1])
    elif len(x)==1:
        return x[0]
    else:
        i=len(x)//2
        return gcd(two_gcd(x[:i]),two_gcd(x[i:]))

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

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

x1 = []

for i in range(N):
    x1.append(abs(x[i]-X))
    
print(two_gcd(x1))

Submission status: Accepted

Solution code:
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
if n>1:
    dif = []
    for i in range(n-1):
        dif.append(x[i+1]-x[i])

    difs = []
    for i in range(n):
        difs.append(abs(s-x[i]))
    res = min(min(dif),min(difs))
    for i in range(res):
        flag = True
        for j in range(n-1):
            if dif[j]%(res-i)!=0:
                flag = False
                break
        if flag:
            res -= i
            break
                
    print(res)
else:
    print(abs(x[0]-s))

Submission status: Accepted

Solution code:
from functools import reduce


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

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)
y = []
for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
print(reduce(gcd, y))

Submission status: Accepted

Solution code:
from fractions import gcd
n,d=map(int,input().split())
x=sorted(list(map(int,input().split()))+[d])
r=x[1]-x[0]
print(min(gcd(x[i+1]-x[i],r) for i in range(n)))

Submission status: Accepted

Solution code:
from fractions import gcd
n,d=map(int,input().split())
x=sorted(list(map(int,input().split()))+[d])
r=x[1]-x[0]
for i in range(n):
    r=gcd(x[i+1]-x[i],r)
print(r)

Submission status: Accepted

Solution code:
import fractions
N, X = map(int,input().split())
x = list(map(lambda y: abs(int(y)-X),input().split()))
m = min(x)

ans = x[0]
for i in range(1,N):
    ans = fractions.gcd(ans,x[i])
    
print(ans)