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:
# 最大公約数
def gcd(a,b):
    if a < b:
        a,b = b,a
    if a % b == 0:
        return b
    else:
        return gcd(b,(a % b))

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

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

print(D)

Submission status: Accepted

Solution code:
from functools import reduce

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

def gcd_l(numbers):
    return reduce(gcd,numbers)


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

for i in range(len(x)):
    y = abs(int(x[i]) - X)
    Y.append(y)
    
D = gcd_l(Y)

print(D)

Submission status: Accepted

Solution code:
import math

def is_common(dists, factor):
    count = 0
#    print("factor: " + str(factor))
#    print(factors)
#    print(factor)
#    print(factors[1:]

    for dist in dists:
        if dist % factor != 0:
            return False
    
    return True

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 = reversed(sorted(divide_to_prime_factors(city_distances[0])))

step = 1
for fact in dist_factors:
    if is_common(city_distances[1:], fact):
        step = fact
        break

#        print(fact_count)
#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: Accepted

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

def gcdlist(l):
    if len(l) == 2:
        return gcd(l[0], l[1])
    f = l.pop()
    s = l.pop()
    m = gcd(f, s)
    l.append(m)
    return gcdlist(l)


def main():
    n, x = map(int, input().split())
    a = [int(v) for v in input().split(' ')]
    a.append(x)
    a.sort()
    dis = [x2 - x1 for x1, x2 in zip(a, a[1:])]
    max_ = 0
    for i in range(n):
        if len(dis) == 1:
            max_ = dis[0]
            break
        try:
            max_ = gcdlist(dis)
        except:
            max_ = 1
    print(max_)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

def gcd(la, lb):
    if la < lb:
        tmp = a
        la = lb
        lb = tmp

    r = la % lb

    while r != 0:
        la = lb
        lb = r
        r = la % lb

    return lb

ans = 1000000001
for i in range(n):
    v = abs(x - a[i])

    if v < ans:
        ans = v

    g = gcd(v, ans)
    if g < ans:
        ans = g

print(ans)

Submission status: Accepted

Solution code:
import functools
import math
import fractions
n, x = map(int, input().split())
xx = list(map(int, input().split()))  # x1 x2 ... xn
xx.append(x)
xx.sort()
diff = []  # 隣接する都市の距離を保存
d = 0
if len(xx) > 2:
    for i in range(1, len(xx)):
        diff.append(abs(xx[i - 1] - xx[i]))
    d = functools.reduce(fractions.gcd, diff)
else:
    d = abs(xx[0] - xx[1])
print(d)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math as mh
import fractions as fr
from functools import reduce

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())
x.append(p)
x.sort()

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

exgcd = reduce(fr.gcd, dx)
print(exgcd)

Submission status: Accepted

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:
  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
  if(ans == 1):
    k = d[0]
    f = []
    j = 2
    while True:
      s = int(k/j)
      if(k % j == 0):
        f.insert(0,s)
      if(s < 1):
        break
      j += 1
    q = len(f)
    for i in range(q):
      u = list(map(lambda x: x% f[q - 1 - i],e))
      if(u.count(0) == n):
        ans = f[q-1-i]
        break

  print(ans)

Submission status: Accepted

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


def main():
    from fractions import gcd
    from functools import reduce

    n, large_x = map(int, input().split())
    x = sorted(list(map(lambda x: int(x) - large_x, input().split())) + [0])

    diff = [0 for _ in range(n + 1)]

    for i in range(1, n + 1):
        diff[i] = x[i] - x[i - 1]

    ans = reduce(gcd, diff)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

def gcd(a, b):
    """Calculate the Greatest Common Divisor of a and b.

    Unless b==0, the result will have the same sign as b (so that when
    b is divided by it, the result comes out positive).
    """
    while b:
        a, b = b, a%b
    return a

def solve():
    x.append(X)

    sorted_x = sorted(x)
    sorted_aaa = []

    aaa = []

    for (i, item) in enumerate(sorted_x):
        if i == 0:
            continue
        aaa.append(int(sorted_x[i] - sorted_x[i - 1]))

    sorted_aaa = sorted(aaa)
    res = 100000000
    # from math import gcd
    for (k, elm) in enumerate(sorted_aaa):
        if len(sorted_aaa) == 1:
            res = sorted_aaa[k]
            break
        if k == 0:
            continue
        g = gcd(sorted_aaa[k - 1], sorted_aaa[k])
        if g < res:
            res = g
    print(res)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
l = input().split(" ")
n = int(l[0])
x = int(l[1])
l = input().split(" ")
for i in range(n):
    l[i] = int(l[i])
for i in range(n):
    l[i] = l[i]- x
l.append(0)
l = sorted(l, reverse=True)
ll = []
for i in range(n):
    ll.append(l[i]-l[i+1])
ll = sorted(list(set(ll)),reverse = True)
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x
for i in range(len(ll)-1):
   ll[i+1] = gcd(ll[i],ll[i+1])
print(ll[-1])

Submission status: Accepted

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

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(max(abs(x[i]-x[i+1]), (abs(x[i+1]-x[i]))))
temp=abs(min(x))
li.append(temp)


if f:
    a=li[0]
    for i in range(len(li)-1):
        a=gcd(a, li[i+1])
    print(a)

Submission status: Accepted

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

N, X  = (int(i) for i in input().split())
x = (int(i) for i in input().split())
x = list(x)
x.append(X)
#print(x)
x = sorted(x)

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

print(ans)

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
xlist =[X]
xlist.extend(list(map(int, input().split())))
dlist =[]
for i in range(N):
    dlist.append(abs(xlist[i+1]-xlist[i]))
g = max(dlist)
for d in dlist:
    g = gcd(g, d)
print(g)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

N, X = map(int, input().split())
if N == 1:
    x = abs(X - int(input()))
    print(x)
else:
    x = list(map(int, input().split()))
    x = list(map(lambda i: abs(X - i), x))
    print(reduce(fractions.gcd, x))

Submission status: Accepted

Solution code:
def g(a,b):x=max([a,b]);y=min([a,b]);return g(y,x%y) if x%y else y
N,X=map(int,input().split());p=[abs(int(i)-X) for i in input().split()];ans=p[0]
for i in range(1,N):ans=g(ans,p[i])
print(ans)

Submission status: Accepted

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:
        x %= max_fact
        if x > 0:
            tmp = max_fact
            max_fact = x
            x = tmp
    if max_fact==1:
        break

print(max_fact)

Submission status: Accepted

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

if x in x_list:
    pass
else:
    x_list.append(x)
    x_list.sort()

min_diff = 99999999999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()
print(1)

Submission status: Accepted

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

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

kouho=[abs(l[i]-x) for i in range(n)]

ans=kouho[0]

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

Submission status: Accepted

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

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

i = input().split(' ')
N = int(i[0])
X = int(i[1])
xs = list(map(lambda x: int(x), input().split(' ')))
ds = list(map(lambda x: abs(X-x), xs))
#print(xs)
#print(ds)
l = gcd_list(ds)
print(l)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
import math
from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
ans = reduce(gcd, a)
print(int(ans))

Submission status: Accepted

Solution code:
# import math
import fractions as math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
diff = [x[i] - x[i-1] for i in range(1,len(x))]
gcf = diff[0]
for d in diff:
    gcf = math.gcd(gcf, d)
print(gcf)

Submission status: Accepted

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

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

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

distances = []
for city in cities:
    distances.append(abs(city - x))

result = distances[0]

for d in distances:
  result = gcd(result, d)

print(result)

Submission status: Accepted

Solution code:
import numpy as np

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

n, X = map(int, input().split())
if n==1:
    x = int(input())
    print(abs(x-X))
    quit()    
else:
    x = list(map(int, input().split()))

    a = np.ones(n)*X
    b = np.abs(x - a)
    c = b[1]
    for i in range(n-1):
        c = gcd(c, b[i])
    print(int(c))

Submission status: Accepted

Solution code:
import fractions

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

xx = []

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

if n == 1:
    print(xx[0])
else:
    xg = xx[0]
    for i in range(1,n):
        xg = fractions.gcd(xg,xx[i])
    print(xg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
headData=[int(n) for n in input().split()]
cityNum=headData[0]
pos_x=int(headData[1])
cityList=[int(n) for n in input().split()]
allList=[]
allList.append(pos_x)
for n in cityList:
    allList.append(n)

allList=sorted(allList)

diffList=[]

for n in range(len(allList)-1):
    diffList.append(allList[n+1]-allList[n])

answer = min(diffList)

while True:
    isAnswer = True
    for n in diffList:
        if n % answer != 0:
            isAnswer = False
            break
    if isAnswer:
        print(answer)
        break
    else:
        answer = answer-1

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
_,X,*A=map(int,open(0).read().split())
print(reduce(gcd,[abs(a-X)for a in A]))

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
ans=0
amari=0
big=0
small=0
for i in range(N):
	x[i] = abs(x[i]-X)
if N==1:
	print(x[0])
else:
	ans=x[0]
	for j in range(1,N,1):
		if x[j]>=ans:
			big=x[j]
			small=ans
		else:
			big=ans
			small=x[j]
		while big%small != 0:
			amari=big%small
			big=small
			small=amari
		ans=small
	print(ans)

Submission status: Accepted

Solution code:
import functools
import fractions
 
n,x = map(int,input().split())
cities = list(map(int,input().split()))
if n == 1:
    ans = abs(cities[0] - x)
    print(ans)
else:
    cities.append(x)
    cities.sort()
    dist = []
    for i in range(1,len(cities)):
        dist.append(cities[i] - cities[i-1])
    ans = functools.reduce(fractions.gcd, dist)
    print(ans)

Submission status: Accepted

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


a=B[0]

for j in range(1,N):
    b=B[j]
    if b<a:
        a,b=b,a
    while b!=0:
        a,b=b,a%b
print(a)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
u = list(map(int,input().split()))
def gcd_list(numbers):
    gct = numbers[0]
    for i in range(len(numbers)-1):
        r = numbers[i+1] % gct
        while r != 0:
            ka = r
            r = gct
            gct = ka
            r = r % gct
    return gct
u.append(X)
u.sort()
sa = []
for i in range(len(u)-1):
    sa.append(u[i+1]-u[i])
if len(sa) > 1:
    print(gcd_list(sa))
else:
    print(sa[0])

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
towns = list(map(int,input().split()))
towns.append(X)
towns.sort()
town_diff = [0]*(len(towns)-1)
for i in range(len(towns)-1):
    town_diff[i] = towns[i+1]-towns[i]
town_diff.sort()
if(len(town_diff) == 1):
    gcd = town_diff[0]
elif(len(town_diff) == 2):
    a = town_diff[0]
    b = town_diff[1]
    while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
else:
    a = town_diff[0]
    b = town_diff[1]
    for i in range(len(town_diff)-2):
        while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
        a = gcd
        b = town_diff[i+2]
print(gcd)

Submission status: Accepted

Solution code:
import fractions
n,m=map(int,input().split())
tosi = list(map(int,input().split()))
for i in range(n):
    tosi[i]=abs(m-tosi[i])
answer=min(tosi)
while max(tosi)!=0:
    for i in range(n):
        if tosi[i]%answer==0:
            tosi[i]=0
        else:
            answer=fractions.gcd(answer,tosi[i])
print(answer)

Submission status: Accepted

Solution code:
import fractions

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

a = list(map(int, input().split()))
a = list(map(lambda x: abs(x-start),a))
a.sort()
D = a[0]

for i in range(1,len(a)):
  diff = a[i] - a[i-1]
  D = fractions.gcd(diff, D)

  if D == 1:
    print('1')
    exit()

print(D)

Submission status: Accepted

Solution code:
import numpy as np

N,X = map(int,(input().split()))
city_list = list(map(int,(input().split())))
city_list.append(X)
i = 0
#city_list = []
#city_list.append(list(map(int,(input().split()))))

def gcd(p,q):
	while q > 0:
		p,q = q, p%q
	return p
  
#print(city_list)
#print(np.diff(sorted(city_list)))
city_diff = np.diff(sorted(city_list))

if N == 1:
	gcd_val = city_diff[0]
elif N == 2:
	gcd_val = gcd(city_diff[0],city_diff[1])
else:
	gcd_val = gcd(city_diff[0],city_diff[1])
	for i in range(i+2,N):
		gcd_val = gcd(gcd_val,city_diff[i])

print(gcd_val)

Submission status: Accepted

Solution code:
from fractions import gcd

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

m = abs(A[0]-x)

for a in A:
    m = gcd(m, abs(a-x))

print(m)

Submission status: Accepted

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

def gcd_list(l):
    # print(l)
    if len(l) == 1:
        return l[0]
    temp = [gcd(l[0],l[1])]
    n = 0
    while(n<len(l)-2):
        # print(temp)
        temp.append( gcd(temp[n], l[n+2]) )
        n = n+1
    # print(temp)
    return(temp[len(temp)-1])

n, start = map(int, input().split(" "))
li = list(map(int, input().split(" ")))
diff = min(li) - start
if(len(li) == 1):
    print(abs(diff))
else:
    li.append(start)
    diff = min(li) - start
    for i in range(len(li)):
        li[i] = li[i] - start - diff
    # print(li)
    print(gcd_list(li))

Submission status: Accepted

Solution code:
#import math
from functools import reduce

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

    return reduce(gcd, numbers)


input_list1 = list(map(int, input().split()))
input_list2 = list(map(int, input().split()))
#input_list1 = [3, 81]
#input_list2 = [33, 105, 57]
N = input_list1[0]
X = input_list1[1]

#print('N:', N)
#print('X:', X)

# 都市のリストにXを追加し、小さい順にソートする
input_list2.append(X)
input_list2.sort()
#print(input_list2)

# それぞれの差を取る
ans_list = []
for i, target in enumerate(input_list2):
    if i == N:
        break
    aa = input_list2[i + 1] - input_list2[i]
    #print(input_list2[i + 1], '-' , input_list2[i])
    ans_list.append(aa)

# 重複排除
ans_list = set(ans_list)

# 最大公約数を求める
if len(ans_list) > 1:
    print(gcd_list(ans_list))
else:
    print(min(ans_list))

Submission status: Accepted

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)

def zako(m,n):
    s=max(m,n)
    t=min(m,n)
    while s%t!=0:
        ss =s%t
        s=t
        t=ss
    else:
        return t
dodo=b[0]
for j in range(N-1):
    bobo = zako(b[j+1],dodo)
    dodo = bobo
print(dodo)

Submission status: Accepted

Solution code:
import sys
from functools import reduce

import numpy


def main():
    lines = [list(map(int, x.strip().split())) for x in sys.stdin.readlines()]
    N, X = lines[0]
    location = sorted(lines[1] + [X])
    if len(location) == 1:
        print(location[0] - X)
    else:
        location = numpy.array(location)
        sub = location[1:] - location[:-1]
        result = reduce(gcd, sub)
        print(result)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8


def solve_gcd_from_list(number_list):
    if len(number_list) == 1:
        return number_list[0]

    if len(number_list) == 2:
        return solve_gcd(number_list[0], number_list[1])
    mid = len(number_list) // 2
    return solve_gcd(solve_gcd_from_list(number_list[:mid]), solve_gcd_from_list(number_list[mid:]))


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


if __name__ == '__main__':
    N, X = map(int, input().split())
    cities = list(map(int, input().split()))

    cities.append(X)
    cities.sort()

    distance_list = []

    for i in range(N):
        distance_list.append(cities[i+1]-cities[i])

    if len(distance_list) == 1:
        D = distance_list[0]
    else:
        D = solve_gcd_from_list(distance_list)
    print(D)

Submission status: Accepted

Solution code:
def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z


N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_list.append(X)
x_list.sort()
y_list=[]
for i in range(N):
    y_list.append(x_list[i+1]-x_list[i])
z_list=list(set(y_list))
if len(z_list)==1:
    print(z_list[0])

else:
    for i in range(len(z_list)-1):
        z_list[i+1]=gcd(z_list[i],z_list[i+1])
    print(z_list[-1])

Submission status: Accepted

Solution code:
import math
import fractions
from functools import reduce

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

saList=[]
for i in range(len(xList)):
  saList.append(abs(x-xList[i]))

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

Submission status: Accepted

Solution code:
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())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = gcd(abs(xlist[i]-x),ans)
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
from functools import reduce


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


def _gcd(*numbers):
    return reduce(math.gcd, numbers)

#def gcd(numbers):
#    return reduce(np.gcd, numbers)

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


def gcd_n(numbers):
  '''Returns GCD of given n numbers.
  Argument: numbers - List of given numbers
  '''
  return reduce(lambda x, y: gcd(x, y), numbers)



N,X=spaceinput()

x=spaceinput()

x.append(X)
x=sorted(x)
d=[]
for i,xx in enumerate(x[:-1]):
    d.append(x[i+1]-x[i])

#print(d)

#print( np.gcd(12, 20))
print(gcd_n(d))

Submission status: Accepted

Solution code:

#coding: utf-8
import numpy as np
from functools import reduce

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

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

y = np.asarray(list(map(int,input().split())))
y -= x
y = map(abs,y)

print(reduce(gcd, y))

Submission status: Accepted

Solution code:
def GCU(m,n):
    if not n:
        return m
    else:
        return GCU(n, m%n)

a,b=map(int,input().split())
l=list(map(int,input().split()))
l.append(b)
l.sort()
ll=[]
for i in range(len(l)-1):
    ll.append(l[i+1]-l[i])
ll.sort()
s=ll[0]
for i in ll:
    s=GCU(s,i)
print(s)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xl = [int(_) for _ in input().split()]
for i in range(n):
    if x > xl[i]:
        xl[i] = x - xl[i]
    else:
        xl[i] = xl[i] - x


def gcd(a, b):
    if a < b:
        x_a = b
        x_b = a
    else:
        x_a = a
        x_b = b
    while(1):
        if x_a < x_b:
            tmp = x_a
            x_a = x_b
            x_b = tmp
        x_a %= x_b
        if x_a == 0:
            break
    return x_b

    
x_gcd = xl[0]
if n > 1:
    for i in range(1, n):
        x_gcd = gcd(x_gcd, xl[i])
print(x_gcd)

Submission status: Accepted

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

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

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

ans = city[0]
for num in city:
    ans = gcd(ans, num)

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=[0]*N
x_d[0]=abs(X-x[0])
for i in range(N-1):
	x_d[i+1]=abs(x[i+1]-x[i])
	
temp=x_d[0]
least=temp
for i in range(N-1):
	if x_d[i+1] > temp:
		temp=gcd(x_d[i+1],temp)
	else:
		temp=gcd(temp, x_d[i+1])
		
	if temp < least:
		least=temp
		
print(least)

Submission status: Accepted

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

kakunin=10**10

if N==1:
    if X<S[0]:
        print(S[0]-X)
        exit()
    else:
        print(X-S[0])
        exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

xs = [int(i) for i in input().split()]
ls = [abs(i-x) for i in xs]


print(gcd_list(ls))

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
for i in range(N):
    A[i] = abs(A[i] - X)
g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])
print(g)

Submission status: Accepted

Solution code:
def euclid(a,b):
	c=0
	if (a-b)<0:
		c=a
		a=b
		b=c
	r=-1
	while r!=0:
		r=a%b
		a=b
		b=r
	return a

N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
	x[i]=x[i]-X
	if x[i]<0:
		x[i]=x[i]*(-1)
D=x[0]
d=x[0]
for j in range(N-1):
	D=euclid(d,x[j+1])
	d=D
print(D)

Submission status: Accepted

Solution code:
# encoding: utf-8
import math

N, X = map(int, input().split())
x = sorted(list(map(int, input().split())) + [X])

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

# Greatest common factor
# print(x)
GCF = x[1] - x[0]
x_min = x[0]
for i, xi in enumerate(x):
    if i == 0: continue
    GCF = gcf2(GCF, (xi - x_min))

print(GCF)

Submission status: Accepted

Solution code:
import sys

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

x.append(X)
x.sort()

d = []
for i in range(N):
    d.append(x[i + 1] - x[i]) #階差

d.sort()

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

D = d[0]
for i in range(len(d) - 1):
    D = gcd(d[i + 1], D)



print(D)

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(n):
  a.append(x[i+1]-x[i])
  
h = min(a)
gcd = 1
for i in range(h,0,-1):
  if h%i == 0:
    if all(a[j]%i == 0 for j in range(n)):
      gcd = i
      break
      
print(gcd)

Submission status: Accepted

Solution code:
import math

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

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

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

#print(X)

an=X[0]



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


def lcm(a,b):
    return a*b//gcd(a,b)



#print(lcm(2,9))

for i in range(n):
    an=gcd(an,X[i])

    #print(str(an)+" "+str(X[i]))

print(an)

Submission status: Accepted

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

xl.append(x)
xl.sort()

onesam = 0

if len(xl) == 1:
    print(abs(xl[0] - x))
    exit()

for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = abs(one_sa)
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            while big % short != 0:
                short = short -1
#                 for k in range(2,short+1):
#                     if short % k == 0:
#                         short = short // k
#                         break
            onesam = short
            
print(onesam)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  9/ 8 21:51:51 2018

# Usage
#
"""
from fractions import gcd
from functools import reduce
def input_nlines_multi():
    initial_pos = int(input().split(" ")[1])
    poses = [int(i) for i in input().split(" ")]

    return [initial_pos, poses]

def get_each_GCD(initial_pos, poses):
    """
    >>> get_each_GCD(3, [1,7,11])
    2
    >>> get_each_GCD(81, [33,105,57])
    24
    >>> get_each_GCD(1, [1000])
    999
    """
    target_nums = [abs(p - initial_pos) for p in poses]

    return reduce(gcd, target_nums)

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    print(get_each_GCD(*input_nlines_multi()))

Submission status: Accepted

Solution code:
import math
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n, x_s = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
#n, x_s = [3, 3]
#x = [1,7,11]
x.append(x_s)
y = sorted(x)
# print(y)
# print([i - y[0] for i in y][1:])
print(gcd_list([i - y[0] for i in y][1:]))
# print(y)
# print(gcd_list([i - x_s for i in y].remove(0)))

Submission status: Accepted

Solution code:
#import math
from functools import reduce

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

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

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(gcd, x)
    print(D)