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:
import bisect
def gcd(x , y):
    max_val = max(x , y)
    min_val = min(x , y)
    while min_val != 0:
        max_val , min_val = min_val , max_val % min_val
    return max_val
N , X = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
split_idx = bisect.bisect_left(x , X)
BeforeList = x[:split_idx]
AfterList = x[split_idx:]
now = X
ans = 0
DistanceList = []
for val in AfterList:
    distance = abs(val - now)
    DistanceList.append(distance)
    now = val
for val in BeforeList:
    distance = abs(val - now)
    DistanceList.append(distance)
    now = val

ans = DistanceList[0]
for i in range(1,len(DistanceList)):
    ans = gcd(DistanceList[i] , ans)
print(ans)

Submission status: Accepted

Solution code:
import fractions


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

ans = abs(x-X[0])
for xi in X:
    a = abs(x-xi)
    ans = fractions.gcd(ans, a)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
#from math import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
dif = [abs(x[i+1]-x[i]) for i in range(N-1)]
ans = abs(x[0]-X)
for i in range(N-1):
    ans = gcd(ans,dif[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
ds = [xs[i+1]-xs[i] for i in range(N)]
ans = ds[0]
for i in range(1, N):
    ans = gcd(ans, ds[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

N,X=map(int, input().split())
Towns=list(map(int, input().split()))
dist=[]
for i in Towns:
    dist.append(abs(i-X))

print(gcd(*dist))

Submission status: Accepted

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

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

if len(d) == 1:
    print(d[0])
else:    
    g = gcd(d[0], d[1])
    for i in range(2,N):
        g=gcd(g,d[i])
    print(g)

Submission status: Accepted

Solution code:
from functools import reduce
import fractions

n, x = map(int, input().split())
cities = list(map(lambda k: abs(int(k)-x), input().split()))
ans = reduce(fractions.gcd, cities)
print(ans)

Submission status: Accepted

Solution code:
import fractions

n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x2=sorted(x)
a=x2[1]-x2[0]
if len(x2)==2:
    print(a)
else:
    #print(x2)
    for i in range(1,n):
        b=x2[i+1]-x2[i]
        ans=fractions.gcd(a,b)
        a=ans
    print(ans)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
def gcd(a, b):
    if a < 0: a = -a
    if b < 0: b = -b
    while b > 0:
        (a, b) = (b, a % b)
    return a

N, X = inpl()
x = inpl()
D = abs(x[0]-X)
for i in range(1,N):
  D = gcd(D, x[i]-X)
print(D)

Submission status: Accepted

Solution code:
import fractions

n,X=map(int,input().split())
x=list(map(int,input().split()))
ans=abs(x[0]-X)
for i in range(1,n):
    b=abs(x[i]-X)
    ans=fractions.gcd(ans,b)
print(ans)

Submission status: Accepted

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

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

ans = Y[0]
for y in Y:
  ans = gcd(ans,y)
print(ans)

Submission status: Accepted

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

# dist内の最大公約数を求めればよい
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
res = dist[0]
for i in range(1, N):
    res = gcd(res, dist[i])

print(res)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

n,x = map(int, input().split())
dist_list = [abs(int(x_i)-x) for x_i in input().split()]

print(reduce(gcd, dist_list))

Submission status: Accepted

Solution code:
import fractions

n, x = map(int, input().split())
a = list(map(int, input().split()))
v = abs(x - a[0])
for i in range(1, n):
    v = fractions.gcd(v, abs(x - a[i]))
print(v)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd
def solve(N: int, X: int, x: "List[int]"):
    ans = abs(X-x[0])
    for i in range(N):
        ans = gcd(ans, abs(X-x[i]))
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X, x)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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



xl = [i-x for i in xl]

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


ans = abs(xl[0])
for xx in xl:
    ans = abs(gcd(ans, xx))

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
import numpy as np
N, X = map(int, input().split())
xlist = np.array(list(map(int, input().split())))
xabs = np.abs(xlist - X)
num = xabs[0]
for x in xabs:
    num = gcd(x, num)
print(num)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
xl = map(lambda _: abs(_ - x),map(int, input().split()))
ans = reduce(gcd, xl)
print(ans)

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=abs(x-a[0])
a.sort()
if n==1:
    print(abs(x-a[0]))
else:
    cnt=abs(a[1]-a[0])
    for j in range(n-1):
        cnt=fractions.gcd(abs(a[j+1]-a[j]),cnt)
    for i in range(n):
        ans=fractions.gcd(abs(x-a[i]),ans)
    print(fractions.gcd(ans,cnt))

Submission status: Accepted

Solution code:
N, X = [int(x) for x in input().split()]
xn = sorted(list(set([abs(int(x) - X) for x in input().split()])))
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)

if N == 1:
  print(xn[0])
else:
  n = (gcd(xn[0], xn[1]))
  for x in xn[2:]:
    n = gcd(x, n)
  else:
    print(n)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

N, X = map(int, input().split(' '))
city = list(map(int, input().split(' ')))
for i in range(N):
    city[i] = abs(city[i] - X)
    
def gcd(numbers):
    return reduce(fractions.gcd, numbers)

if N == 1:
    ans = city[0]
else:
    ans = gcd(city)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
Xs = list(map(int, input().split()))
ans = abs(X-Xs[0])
for x in Xs[1:]:
    ans = gcd(ans, abs(X-x))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
#それぞれの間の距離の最大公約数
l.append(x)
l = list(set(l))
l.sort()

ans = l[1]-l[0]
for i in range(2,len(l)):
  num = l[i]-l[i-1]
  ans = gcd(ans,num)
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

d = [l[i+1] - l[i] for i in range(n)]

d.sort()

print(gcd(d))

Submission status: Accepted

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

dist = [abs(X - D[i]) for i in range(N)]

def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a % b)
    
D = 0   
    
for i in range(N):
  D = gcd(D,dist[i])
  
print(D)

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x=sorted(x)
dif=[0]*(len(x)-1)
for i in range(len(x)-1):
  dif[i]=x[i+1]-x[i]

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

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

print(ans)

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-10 12:28:14(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

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

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())

    res = functools.reduce(gcd, [abs(x[i+1] - x[i]) for i in range(n)])

    print(res)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

d = []
d.append(abs(X-x[0]))
gc = d[0]
for i in range(1, n):
	d.append(abs(X-x[i]))
	gc = fractions.gcd(d[i], gc)
print(gc)

Submission status: Accepted

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

if N == 1:
    ans = x[0]

else:
    ans = fractions.gcd(x[0],x[1])
    for n in range(2,N):
        ans = fractions.gcd(ans,x[n])

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import fractions


n,x = [int(x) for x in stdin.readline().rstrip().split()]

li = list(map(int,stdin.readline().rstrip().split()))
lin = []
for i in range(len(li)):
    lin.append(abs(li[i]-x))
poi = lin[0]
for i in range(len(lin)-1):
    poi = fractions.gcd(poi,lin[i+1])

print(poi)

Submission status: Accepted

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

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

dif = []

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

ans = dif[0]

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

print(ans)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import fractions
import math

N,X=two_int()

city=many_int()

temp = list(map(lambda x : abs(x-X), city))


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

Submission status: Accepted

Solution code:
import fractions
import functools

def f_gcd(numbers):
  return functools.reduce(fractions.gcd, numbers)
  
n, x = map(int, input().split())
X = list(map(lambda a:abs(int(a)-x), input().split()))
print(f_gcd(X))

Submission status: Accepted

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

A.append(X)
A.sort()
diffs = [A[i+1] - A[i] for i in range(N)]

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


ans = diffs[0]
for d in diffs:
    ans = gcd(ans, d)

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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

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

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

arr1 = [(i-x if i-x>=0 else x-i) for i in arr]

print(gcd(*arr1))

Submission status: Accepted

Solution code:
import fractions
N, X = map(int,input().split())
x = list(map(int,input().split()))
x.extend([X])
x.sort()
sa = [0]*(N)
for i in range(N):
    sa[i] = x[i+1]-x[i]
ans = max(x)
if len(sa) == 1:
    ans = sa[i]
else:
    for i in range(N-1):
        ans = min(ans, fractions.gcd(sa[i],sa[i+1]))
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
def f(n):
    return abs(X-int(n))
x = list(map(f, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
if N > 1:
    res = gcd(x[0], x[1])
    for i in range(2, N):
        res = gcd(x[i], res)
    print(res)
else:
    print(x[0])

Submission status: Accepted

Solution code:
def GCD(x,y):
    if y>x :
        x,y = y,x
    mod = x%y
    return GCD(y,mod) if mod!=0 else y

N,X = map(int,input().split())
x = list(map(int,input().split()))
for i in range(N-1,0,-1):
    x[i] = abs(x[i]-x[i-1])
x[0] = abs(x[0]-X)
gcd = x[0]
for i in range(1,N):
    gcd = GCD(gcd,x[i])
print(gcd)

Submission status: Accepted

Solution code:

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

M = [abs(i - X) for i in L]

def gcd(a,b):
    if b==0: 
        return a 
    return gcd(b,a%b)
    
D = 0 
for i in range(0,len(M)): 
    D = gcd(D,M[i])

print(D)

Submission status: Accepted

Solution code:
import fractions

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

dp = [0]*n
for i in range(n):
    if i == 0:
        dp[0] = s[0]
    else:
        dp[i] = fractions.gcd(dp[i-1],s[i])
print(dp[-1])

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
l=[abs(i-k) for i in l]
def gcd(a,b):
    if b==0: 
        return a 
    return gcd(b,a%b)
g=0 
for i in l: 
    g=gcd(g,i)
print(g)

Submission status: Accepted

Solution code:
import fractions

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

L = list(map(int,input().split()))
y = []
for i in range(n):
  y.append(abs(L[i]-x))
tmp = y[0]

for i in range(n-1):
  tmp = fractions.gcd(tmp,y[i+1])
print(tmp)

Submission status: Accepted

Solution code:
import fractions
N, M = map(int, input().split())
X = list(map(int, input().split()))

Y=[0]*N

for i in range(N):
    Y[i]=abs(X[i]-M)

tmp=Y[0]
for i in range(N-1):
    tmp=fractions.gcd(tmp,Y[i+1])

print(tmp)

Submission status: Accepted

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

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

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

ans = fix_x[0]
for i in range(len(fix_x)):
    ans = gcd(ans, fix_x[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a, b):
    return gcd(b, a%b) if b else a

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

x.append(X)
x = sorted(x)

s = [0 for i in range(N)]
for i in range(N):
    s[i] = x[i+1] - x[i]
    
ans = s[0]
for i in range(N):
    ans = gcd(ans, s[i])

print(ans)

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


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

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

zahyo.append(X)
zahyo.sort()

distant = []
for i in range(N):
    distant.append(zahyo[i+1] - zahyo[i])
# print(zahyo)
# print(distant)
ans = distant[0]
for i in range(1, N):
    ans = gcd(ans, distant[i])

print(ans)

Submission status: Accepted

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

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

diff = [abs(x[i] - X) for i in range(N)]
ret = diff[0]
for i in range(1, N) :
    ret = gcd(ret, diff[i])
print(ret)

Submission status: Accepted

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

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

for i in range (0,N):
  x[i] = abs(x[i] - X)
x.sort()
ans = max(x)
for i in range (0,N-1):
  g = gcd(x[i],x[i+1])
  ans = min(g,ans)
print(ans)

Submission status: Accepted

Solution code:
n,s=map(int,input().split())
l=[abs(int(i)-s) for i in input().split()]
ans=l[0]
def gc(a,d):
  ai=a;bi=d
  a,d=min(ai,bi),max(ai,bi)
  if a==0:return d
  else:return gc(d%a,a)
  
  
for i in l:
  ans=gc(ans,i)
print(ans)

Submission status: Accepted

Solution code:
n,s=map(int,input().split())
l=[abs(int(i)-s) for i in input().split()]
ans=l[0]
def gc(a,d):
  ai=a;bi=d
  a,d=min(ai,bi),max(ai,bi)
  if a==0:return d
  else:return gc(d%a,a)
  
  
for i in l:
  ans=gc(ans,i)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
A = list(map(int, input().split()))

ans = abs(A[0] - X)

for x in A[1:]:
    ans = gcd(ans, abs(x - X))
    if ans == 1:
        break

print(ans)

Submission status: Accepted

Solution code:
import fractions as math
n,x = map(int,input().split())
list1 = list(map(int,input().split()))
ans = max(abs(x-list1[0]),abs(list1[-1]-x))
for i in range(n):
	gcd = math.gcd(ans,abs(x-list1[i]))
	ans = min(ans, gcd)

print(ans)

Submission status: Accepted

Solution code:
import fractions


N,M = map(int,input().split())
ary = [abs(i - M) for i in map(int,input().split())]
ans = ary[0]
for i in range(1,N):
    ans =  fractions.gcd(ans,ary[i])
print(ans)

Submission status: Accepted

Solution code:
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_d = [abs(X-x1) for x1 in x]
a = x_d[0]
for i in range(n-1):
    a = gcd(a,x_d[i+1])
print(a)

Submission status: Accepted

Solution code:
def GCD(x,y):
    x,y=max(abs(x),abs(y)),min(abs(x),abs(y))
    if y==0:
        return x
    elif x%y==0:
        return y
    else:
        return GCD(y,x%y)

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

ans=0

for xi in x:
    ans=GCD(ans,xi-X)

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n,x = map(int,input().split())
X = [abs(x-int(i)) for i in input().split()]
print(reduce(gcd,X))

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()))
X = [abs(a-x) for a in X]
print(reduce(gcd,X))

Submission status: Accepted

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)
def gcd(a,b):
    if a<b:
        a,b=b,a
    if b==0:
        return a
    else:
        return gcd(b,a%b)
ans=x[0]
for i in range(1,n):
    ans=gcd(x[i],ans)
print(ans)

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
ary = list(map(int, input().split()))
arr = [abs(i - X) for i in ary]
ans = arr[0]
for i in range(1,N):
    ans = fractions.gcd(ans, arr[i])
print(ans)

Submission status: Accepted

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

print (ans)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = (int(i) for i in input().split())

x = [abs(int(i) - X) for i in input().split()]  
for i in range(1,N):
	x[i] = gcd(x[i-1], x[i])

print(x[-1])

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
  A[i]=abs(X-A[i])
for i in range(N-1):
  while(A[i]>0):
    A[i+1]%=A[i]
    A[i],A[i+1]=A[i+1],A[i]
print(A[N-1])

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split())
x=list(map(int,input().split()))
diff = [abs(x[i]-X) for i in range(N)]
ans=diff[0]
for i in range(1,N):
  ans=fractions.gcd(ans,diff[i])
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x_list = [int(e) for e in input().split()]

#数直線上に N 個の都市があり、i 番目の都市は座標 xiにあります。
#あなたの目的は、これら全ての都市を 1度以上訪れることです。
#あなたは、はじめに正整数 Dを設定します。
#その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行います。

#移動 1: 座標 y から座標 y+D に移動する
#移動 2: 座標 y から座標 y−D に移動する

#全ての都市を 1度以上訪れることのできる D の最大値を求めてください。

x_list = [abs(x_list[i]-X) for i in range(N)]

def make_divisors(n):
    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)
    return divisors

for divisors in make_divisors(min(x_list)):
  devided_list = [x_list[i]%divisors for i in range(N)]
  if sum(devided_list)==0:
    print(divisors)
    break

Submission status: Accepted

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

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

if n == 1:
  a.append(a[0])
  n = n+1
d = []
for i in range(n):
  y = abs(a[i] - x)
  d.append(y)

b = gcd(d[0],d[1])
for i in range(n):
	b = gcd(b,d[i])
print(b)

Submission status: Accepted

Solution code:
def main():
    N, X = (int(i) for i in input().split())
    x = [abs(int(i) - X) for i in input().split()]
    from fractions import gcd
    for i in range(1,N):
        x[i] = gcd(x[i-1], x[i])

    print(x[-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
P=sorted(list(map(int,input().split())))
P=[abs(i-X) for i in P]

def gcd_list(L):
    b=min(L)
    for i in L:
        while True:
            if i%b==0:
                break
            c=b
            b=i%b
            i=c
    return(b)

print(gcd_list(P))

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= X
z = 0
from fractions import gcd
for i in range(N):
    z = gcd(z,A[i])
print(abs(z))

Submission status: Accepted

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

import fractions
from functools import reduce

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N,X=map(int,input().split())
x=list(map(int,input().split()))
if N == 1:
  print(abs(x[0]-X))
  exit()
x.append(X)
x.sort()
y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
print(reduce(gcd,y))

Submission status: Accepted

Solution code:
from fractions import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))
if N == 1:
  print(abs(x[0]-X))
  exit()
x.append(X)
x.sort()
y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
ans=gcd(y[0],y[1])
for i in range(2,len(y)):
  ans=gcd(ans,y[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

if N == 1:
    if X < x_list[0]:
        x_list.insert(0, X)
    else:
        x_list.insert(1, X)
else:
    for i in range(N-1):
        if x_list[i] < X < x_list[i+1]:
            x_list.insert(i+1, X)
        else:
            x_list.append(X)

x_list.sort()

x_diff = [0]*N
for i in range(N):
    x_diff[i] = x_list[i+1] - x_list[i]

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

Submission status: Accepted

Solution code:
import fractions

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

x.append(X)
x.sort()

for i in range(len(x)-1):
    dif=x[i+1]-x[i]
    if i==0:
        ans=dif
    elif dif<ans:
        ans=dif
    elif dif%ans!=0:
        ans=fractions.gcd(ans,dif)

print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x1 = list(map(int, input().split()))
x2 = [0]*N
for i in range(N):
  x2[i] = abs(x1[i]-X)
import fractions
ans = x2[0]
for i in range(N-1):
  ans = fractions.gcd(ans,x2[i+1])
print(ans)

Submission status: Accepted

Solution code:
import math
from fractions import gcd
N, X = map(int,input().split())
x = list(map(int,input().split()))
L = []
for i in range(N):
    y = math.fabs(X-x[i])
    y = int(y)
    L.append(y)
ans = L[0]
for i in range(len(L)):
    ans = gcd(ans,L[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

x_diff = [abs(y-X) for y in x]
for i in range(N):
  if i == 0:
    tmp = x_diff[i]
  else:
    tmp = gcd(tmp, x_diff[i])
print(tmp)

Submission status: Accepted

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

n,X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if n==1:
    print(abs(x[0]-X))
    exit()
y = [ x[i]-x[i-1] for i in range(1,n)]
d = abs(X-x[0])
for i in range(n-1):
    d = gcd(d, y[i])
print(d)

Submission status: Accepted

Solution code:
# ABC109
import fractions
from functools import reduce
def gcd_list(lst):
    return reduce(fractions.gcd, lst)

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

diff_list = [0] * (N)
for i in range(N):
    diff_list[i] = x[i+1] - x[i]


ans = gcd_list(diff_list)
print(ans)

Submission status: Accepted

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)
m = x[0]
import fractions
for i in range(1, N):
    m = fractions.gcd(m, x[i])
print(m)

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
lst=[]
for i in range(N):
  lst.append(abs(X-x[i]))
  
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if a==b:
    return a
  else:
    if a%b==0:
      return b
    else:
      return gcd(b,a%b)
if N==1:
  print(lst[0])
else:
  tmp=gcd(lst[0],lst[1]) 
  if N==2:
    print(tmp)
  elif N>=3:
    for i in range(2,N):
      tmp=gcd(tmp,lst[i])
    print(tmp)

Submission status: Accepted

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

l=list()

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

for i in range(n):
  if x[i]!=s:
    l.append(abs(x[i]-s))

d=l[0]
for i in range(1,len(l)):
  d=lcd(d,l[i])

print(d)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

x.append(X)
x = sorted(x)
diff_x = []
for i in range(len(x)-1):
    diff_x.append(x[i+ 1] - x[i])


ans = reduce(gcd, diff_x)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
if __name__ == "__main__":
    N, X = map(int, input().split())
    x = list(map(int, input().split()))

    diff = [0] * N
    for i in range(N):
        diff[i] = abs(x[i] - X)

    ans = diff[0]
    for i in range(N):
        ans = gcd(ans, diff[i])

    print(ans)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
A=[]*n
A[:]=map(int,input().split())
for i in range(n):
  A[i]=abs(A[i]-x)
if len(A)==1:
  print(A[0])
else:
  def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
      
  left=[0]*n
  right=[0]*n
  for i in range(1,n):
    left[i]=gcd(left[i-1],A[i-1])
    right[n-1-i]=gcd(right[n-i],A[n-i])
 
  ans=10**9
  for i,j in zip(left,right):
    ans=min(ans,gcd(i,j))
  print(ans)

Submission status: Accepted

Solution code:
import fractions
n,x0= map(int, input().split())
x= list(map(int, input().split()))
x.append(x0)
a=min(x)
for i in range(n+1):
    x[i]-=a
for i in range(n):
    x[i+1]=fractions.gcd(x[i],x[i+1])
print(x[-1])

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*n
for i in range(n):
  a[i]=abs(l[i]-x)
a.sort()
from fractions import gcd
from functools import reduce
def gcdl(list):
  return reduce(gcd,list)
print(gcdl(a))

Submission status: Accepted

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

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

g=abx[0]
for i in range(N-1):
  g=gcd(g,abx[i+1])

print(g)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
l=list(map(int,input().split()))

for i in range(N):
    l[i]=abs(l[i]-K)
    
def ins(num):
    l=[]
    for i in range(1,int(num**0.5//1)+1):
        if num%i==0:
            l.append(i)
            l.append(num//i)
    return l

cand=(ins(min(l)))

cand.sort()
#print(cand)

count=0

for item in cand:
    temp=0
    for target in l:
        if target%item==0:
            temp+=1
    count=max(count,temp)
    if count==temp:
        ans=item
print(ans)

#遅いかも

Submission status: Accepted

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)  #ユークリッドの互除法

def gcdlist(L):
    a = L[0]-X
    for i in L:
        a = gcd(a, abs(i-X))
    return a
    
    
print(gcdlist(x))

Submission status: Accepted

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

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

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

# ここの計算量間に合わないでしょ...
c = m[0]
for i in range(1, N):
    if c == 1: break
    c = gcd(c, m[i])

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

absli = list(map(lambda x: abs(x - y), li))

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

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