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 sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

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

if __name__ == "__main__":
    n,x = map(int,input().split())
    X = list(map(int,input().split()))
    X.sort()
    a = bisect.bisect_left(X,x)
    X.insert(a,x)
    ans = []
    for i in range(1,len(X)):
        diff = X[i] - X[i-1]
        ans.append(diff)
    d = ans[0]
    for i in range(1,len(ans)):
        d = gcd(d,ans[i])
    print(d)

Submission status: Accepted

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

if n >= 2:
	ans = fractions.gcd(b[0], b[1])
	for i in range(2, n):
		ans = fractions.gcd(ans, b[i])
	print(ans)
if n == 1:
	print(b[0])

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 fractions import gcd
n,x=map(int, input().split())
town=list(map(int, input().split()))+[x]
town.sort()
if n == 1:
    town.remove(x)
    print(abs(town[0]-x))
    exit()

d1 = abs(town[0]-town[1])
d2 = abs(town[1]-town[2])
ans = gcd(d1,d2)

for i in range(2,n):
    d = abs(town[i]-town[i+1])
    ans = gcd(d,ans)
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    big, small = max(a, b), min(a, b)
    if big % small == 0:
        return small
    div = None
    while big % small != 0:
        div = big % small
        big, small = small, div
    else:
        return div


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

d = x[0]
for xi in x[1:]:
    d = gcd(d, xi)
print(abs(d))

Submission status: Accepted

Solution code:
from fractions import gcd

n,x=map(int,input().split())
l=list(map(int,input().split()))+[x]
l.sort()

ans=l[1]-l[0]
for i in range(2,n+1):
  sa=l[i]-l[i-1]
  ans=gcd(ans,sa)

print(ans)

Submission status: Accepted

Solution code:
def main():
    from functools import reduce

    N, X = map(int, input().split())
    A = (int(j) - X for j in input().split())

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

    print(abs(reduce(gcd, A)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

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



ans = abs(z[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - z[i]))
print(ans)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N, X = map(int, input().split())
x = readints()
#print(N, X)
# print(x)

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

Submission status: Accepted

Solution code:
from fractions import gcd
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - a[i]))
print(ans)

Submission status: Accepted

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

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

print(g)

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd
n,x=map(int,input().split())
xl=list(map(int,input().split()))

xl.append(x)


p=min(xl)
ans=x-p
for i in range(n+1):
    ans=gcd(xl[i]-p,ans)
print(ans)

Submission status: Accepted

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

lis = []
for x in Xs:
    lis.append(abs(x-X))

G = 0
for l in lis:
    G = gcd(l, G)
print(G)

Submission status: Accepted

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

x.append(X)
x.sort()

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

g = d[0]
for j in d:
    g = gcd(g, j)
print(g)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,x=map(int, input().split())
    l=list(map(int,input().split()))
    if n==1:
        print(abs(l[0]-x))
    else:
        l.append(x)
        l.sort()
        S=[]
        for i in range(n):
            S.append(l[i+1]-l[i])
        from functools import reduce
        from fractions import gcd
        print(reduce(gcd,S))
resolve()

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,X=mp()
x=lmp()
ans=abs(X-x[0])
for i in range(0,n-1):
    ans=fractions.gcd(ans,abs(x[i]-x[i+1]))
print(ans)

Submission status: Accepted

Solution code:
import fractions
def GCD(a):
    gcd = a[0]
    N = len(a)
    for i in range(1, N):
        gcd = fractions.gcd(gcd, a[i])
    return gcd

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

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

x.append(X)
x.sort()

ans = float("inf")
d = []
for i in range(N):
    d.append(x[i+1] - x[i])

ans = GCD(d)
print(ans)

Submission status: Accepted

Solution code:
import fractions
from collections import deque
from functools import reduce
def gcd(numbers):
    return reduce(fractions.gcd, numbers)
N,X = map(int,input().split())
x = list(map(int,input().split()))
A = deque([])
for i in x:
    A.append(abs(X-i))
print(gcd(list(A)))

Submission status: Accepted

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

from fractions import gcd

now = lin[0]
for i in range(1,n):
    p = gcd(now,lin[i])
    now = p

print(now)

Submission status: Accepted

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

Submission status: Accepted

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

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())
A = list(map(int,input().split()))
B = [0 for _ in range(N)]
for i in range(N):
    if X>A[i]:
        B[i] = X-A[i]
    else:
        B[i] = A[i]-X
D = B[0]
for i in range(1,N):
    D = gcd(D,B[i])
print(D)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    def ngcd(self, A):
        res = A[0]
        for i in range(len(A)):
            if res != 1:
                res = gcd(A[i], res)
        return res

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

    def nlcm(self, A):
        res = A[0]
        for i in range(len(A)):
            res = lcm(res, A[i])
        return res


def resolve():
    n, x = map(int, input().split())
    X = sorted(list(map(int, input().split())))

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

    g = Gcd()
    res = dist[0]
    for i in range(1, len(dist)):
        res = g.gcd(res, dist[i])
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from itertools import accumulate


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


N, X = map(int, input().split())
A = [abs(X - a) for a in map(int, input().split())]
ans = list(accumulate(A, func=GCD))[-1]
print(ans)

Submission status: Accepted

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

x_list.sort()
x_sa=[]
a=x_list[1]-x_list[0]
for i in range(1,n):
  b=x_list[i+1]-x_list[i]
  a=fractions.gcd(a,b)
print(a)

Submission status: Accepted

Solution code:
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
from fractions import gcd
n, x = map(int, input().split())
xx = map(int, input().split())
ans = 0
for i in xx:
    ans = gcd(ans, abs(i - x))
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
  if(a == b):
    return a
  elif(a % b == 0):
    return b
  elif(b % a == 0):
    return a
  elif(a == 1 or b == 1):
    return 1
  elif(a > b):
    return gcd(a- a// b* b, b)
  elif(a < b):
    return gcd(a, b- b// a* a)

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

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

gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Accepted

Solution code:
from fractions import *
from math import *
from functools import reduce

def gcds(*xs):
    return reduce(gcd, xs)

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd(*L))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


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


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

x_arr = [0] * n

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

for i in range(len(x_arr)):
    x_arr[i] = abs(x_arr[i] - x)
print(gcd_list(x_arr))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

for i in x:
    y.append(abs(X-i))

#print(y)
print(gcd_list(y))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

for i in x:
    y.append(abs(X-i))

#print(y)
print(gcd_list(y))

Submission status: Accepted

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

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

from functools import reduce

# X との差
y = [abs(x - X) for x in Xs]
print(reduce(gcd, y))

Submission status: Accepted

Solution code:
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)
    return divisors

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    y = [abs(X-a) for a in x]
    cnt = set(make_divisors(min(y)))
    for d in y:
        tmp = []
        for c in cnt:
            if d%c == 0:
                tmp.append(c)
        cnt.intersection_update(set(tmp))
        if len(cnt) == 1:
            print(1)
            return
    ans = max(cnt)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - Skip

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

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

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

Submission status: Accepted

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

from fractions import gcd

ans=abs(x-x_list[0])
for i in range(1, n):
    x_diff=x_list[i]-x_list[i-1]
    ans=gcd(ans, x_diff)

print(ans)

Submission status: Accepted

Solution code:
import fractions as math

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

a = []
for i in s:
    a.append(abs(i-x))

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])

print(tmp)

Submission status: Accepted

Solution code:
from fractions import gcd
n,x=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(x-a[0]))
    exit()

for i in range(n-1):
    if i==0:
        D=gcd(abs(x-a[i]),abs(x-a[i+1]))
    else:
        D=min(D,gcd(abs(x-a[i]),abs(x-a[i+1])))
    if D==1:
        break
print(D)

Submission status: Accepted

Solution code:
from fractions import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
m = x[1]-x[0]

for i in range(1,N+1):
    n = x[i]-x[i-1]
    v = gcd(m,n)
    m = v

print(m)

Submission status: Accepted

Solution code:
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()
    return divisors

def make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


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

#print(b)
#print(a)
if len(b) >= 2:
  print(make_codivisors(b))
else:
  print(b[0])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n, x = map(int, input().split())
X = list(map(int, input().split()))
X.append(x)
X.sort()
Y = [b - a for a, b in zip(X, X[1:])]

print(gcd_list(Y))

Submission status: Accepted

Solution code:
import numpy as np
import fractions
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = np.diff(a)
if n>1:
    gcd = fractions.gcd(d[0],d[1])
    if n>3:
        for i in range(2,n-1):
            gcd = fractions.gcd(gcd,d[i])
    print(gcd)
else:
    print(d[0])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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

ans = gcd_list(d)
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()
skyks = l[1]-l[0]
for i in range(1,n):
    y = l[i+1]-l[i]
    skyks = gcd(skyks,y)
print(skyks)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    dist = [abs(X - y) for y in x]
    D = dist[0]
    for d in dist:
        D = gcd(D, d)
    print(D)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import functools
import numpy as np

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


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


if n > 1:
    if abs(x[0]-X) == 0:
        ans = euclid(abs(x[1]-X), abs(x[2]-X))
    elif abs(x[1]-X) == 0:
        ans = euclid(abs(x[0]-X), abs(x[2]-X))
    else:
        ans = euclid(abs(x[0]-X), abs(x[1]-X))

    for xi in x[2:]:
        ans = euclid(ans, abs(xi-X))
        if ans == 1:
            break

else:
    ans = abs(x[0] - X)

print(ans)

Submission status: Accepted

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

d = 10**9
for i in range(N):
    newd = abs(X-L[i])
    if newd<d:
        d = newd
        ind = i

near = L[ind]
Y = []
for i in range(N):
    if i!=ind:
        Y.append(abs(near-L[i]))
Y.append(d)

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

X.append(s)
X.sort()

Y = [(X[i] - X[i - 1]) for i in range(1, n + 1)]

print(gcd_list(Y))

Submission status: Accepted

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

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

Submission status: Accepted

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

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

import fractions
ans = X[1] - X[0]

for i in range(n-1):
    ans = fractions.gcd(ans,X[i+2]-X[i+1])
    
print(ans)

Submission status: Accepted

Solution code:
n,x=map(int,input().split()) #n都市xスタート座標
a=list(map(int,input().split()))
import fractions
for i in range(n):
    a[i]=a[i]-x
ans=a[0]
for i in range(1,n):
    ans=fractions.gcd(ans,a[i])
print(abs(ans))

Submission status: Accepted

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

y = a[0]
for i in range(1, n):
  y = fractions.gcd(y, a[i])
print(abs(y))

Submission status: Accepted

Solution code:
def gcd(a, b):
	"""Compute the greatest common divisor of a and b"""
	while b > 0:
		a, b = b, a % b
	return a

def resolve():
	n, x = map(int, input().split())
	pos = list(map(int, input().split()))
	diff = [0]*n
	for i in range(n):
		diff[i] = abs(x - pos[i])
	ans = diff[0]
	for i in range(1, n):
		ans = gcd(ans, diff[i])
	print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

l = list(map(int, input().split()))
l.append(x)
l = sorted(l)
ld = list()
for i in range(n):
    ld.append(l[i+1]-l[i])

a = ld[0]
for i in range(1, n):
    a = fractions.gcd(a, ld[i])

print(a)

Submission status: Accepted

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

DIST = [abs(X-x) for x in XS]

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

Submission status: Accepted

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

lst = []
for n in xlst:
    difference = abs(X - n)
    lst.append(difference)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
def gcd(x, y):
    gcd=fractions.gcd(x, y)
    return gcd

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

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

else:
    for i in range(n):
        a[i]=abs(x-a[i])
    
    ans=gcd(a[0], a[1])

    for i in range(2, n):
        ans=gcd(ans, a[i])
    
    print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

if len(x) == 1:
    print(abs(X - x[0]))
else:
    k = [
        abs(X - p)
        if i == 0
        else
        abs(p - x[i - 1])
        for i, p in enumerate(x)
    ]
    D = gcd(k[0], k[1])
    for n in range(2, N):
        D = gcd(D, k[n])
    
    print(D)

Submission status: Accepted

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


def list_gcd(arr):
    if len(arr) == 1:
        return arr[0]

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


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

print(list_gcd(steps))

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
f = min([a[i+1]-a[i] for i in range(n)])
ans = f
for i in range(n):
    if (a[i+1] - a[i])%f:
        ans = min(ans,(a[i+1] - a[i])%f)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

ans = abs(s - x[0])
for i in x:
    ans = gcd(ans, abs(s - i))
print(ans)

Submission status: Accepted

Solution code:
n,X = map(int,input().split())
l =  list(map(int,input().split()))
l.sort(reverse = True)
ans = 10**10
yakusuu = []
count= 0
if n == 1:
  print(abs(l[0]-X))
  exit()
  
for i in l:
  ans = min(ans,abs(i-X))
  if i-X < 0:
    break

for i in range(1,ans+1):
  if ans%i == 0:
    yakusuu.append(i)

yakusuu.reverse()

for i in yakusuu:
  for j in range(n-1):
    if (l[j]-l[j+1])%i != 0:
      break
    elif (l[j]-l[j+1])%i == 0:
      count += 1
      if count == len(l) - 1:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools
n, x = map(int,input().split())
place = list(map(int,input().split()))
place.append(x)
place.sort()
if n == 1:
    print(place[1] - place[0])
    exit()

k = []
for i in range(1, n+1):
    k.append(place[i] - place[i-1])

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

def gcd(nums):
    return functools.reduce(euclid, nums)

print(gcd(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

gcd = 0

for x in range(N):
    gcd = fractions.gcd(abs(a[x] - X), gcd)
print(gcd)

Submission status: Accepted

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

n, X = map(int, sys.stdin.buffer.readline().split())
x = list(map(int, sys.stdin.buffer.readline().split()))
ans = abs(X - x[0])
for i in x[1:]:
    tmp = abs(X - i)
    if tmp % ans:
        ans = gcd(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
*x, = map(int, input().split())
y = [abs(X-x_i) for x_i in x]
def gcd(a,b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a
ans = y[0]
for i in range(1,N):
    ans = gcd(ans, y[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

if n==1:
    print(abs(x[0]-x0))
    exit()

x.append(x0)
x.sort()
dis=[]
for i in range(1,n+1):
    dis.append(x[i]-x[i-1])

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

print(gcd(dis))

Submission status: Accepted

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

for i in range(n):
    if i == 0:
        now = X[i]
    else:
        now = fractions.gcd(X[i], now)

print(now)

Submission status: Accepted

Solution code:
import fractions

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

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

x.append(X)

x.sort()

dis = []

for i in range(1, n+1):
    dis.append(x[i] - x[i-1])

for i in range(n):
    if i == 0:
        now = dis[i]
    else:
        now = fractions.gcd(dis[i], now)

print(now)

Submission status: Accepted

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

ans=abs(a[0]-x)
for i in range(1,n):
    ans=fractions.gcd(abs(a[i]-x),ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc109


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


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x = [val-X if val >= X else X-val for val in x]
    x = sorted(x)

    # w = [None] * N
    # w[0] = x[0] - X
    # for i in range(1, N):
    #     w[i] = x[i] - x[i-1]

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

    return ans


print(main())