Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

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

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

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

Sample Input 1

3 3
1 7 11

Sample Output 1

2

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

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999



Sample input:
3 3
1 7 11


Sample output:
2

Submission status: Accepted

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

def prim(y):
    p=[]
    while y>1:
        for i in range(2,y+1):
            if y%i==0:
                y//=i
                p.append(i)
                break
    return p
   
ans=1

for i in prim(m):
    if m%i !=0:
        continue
    if set([j%i for j in x]) == {0}:
        ans *= i
        x = [j//i for j in x]
    if set([j%(m//i) for j in x]) == {0}:
        ans *= (m//i)
        x = [j//(m//i) for j in x]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fractions.gcd, xlist)
print(answer)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = [abs(A[0] - x)]

for i in range(n-1):
    B.append(A[i] - A[i+1])
    
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(X)
cities.sort()
cities = [x - cities[0] for x in cities]

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

ans = gcd(cities[1], cities[0])
if len(cities) >= 3:
	for i in range(1, len(cities) - 1):
		ans = gcd(ans, cities[i+1])

print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())


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

A = list(input().split())
B = []
ans = abs(int(A[0])-b)
for i in A:
    aa = abs(int(i) - b)
    ans = gcd(ans, aa)

print(ans)

Submission status: Accepted

Solution code:
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x, ps):
    res = {}
    for prime in ps:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    y = do_prime_fact(x[1] - x[0], primes)
    ps = y.keys()
    ys = [do_prime_fact(x[i+1] - x[i], ps) for i in range(len(x)-1)]
    d = 1
    for k in ps:
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

Submission status: Accepted

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

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


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

print(ans)

Submission status: Accepted

Solution code:
N_X = list(map(int,input().split()))
data = list(map(int,input().split()))
k = 0

for i in data:
    data[k] = abs(i - N_X[1])
    k += 1

m = min(data)
a = []
for i in range(1,m+1):
    if m % i == 0:
        a.append(i)
        a.append(int(m/i))
    if i**2 > m:
        break

a.sort()
a.reverse()

for i in a:
    if all(c%i == 0 for c in data):
        print(i)
        break

Submission status: Accepted

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

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

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

Submission status: Accepted

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


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

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

print(ans)

Submission status: Accepted

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


def main():
    N, X = map(int, input().split())
    dif = list(map(lambda x: abs(int(x) - X), input().split()))

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

main()

Submission status: Accepted

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


def main():
    from fractions import gcd

    n, large_x = map(int, input().split())
    x = sorted(list(map(int, input().split())) + [large_x])
    ans = float('inf')

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

    for k in range(n - 1):
        ans = min(ans, gcd(x[k + 2] - x[k + 1], x[k + 1] - x[k]))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
try:
    from math import gcd # >=Python 3.5
except:
    from fractions import gcd # <Python 3.5 (AtCoder : 3.4)

def solve(X, xs):
    xs = list(xs) + [X]
    xs.sort()
    zs = [x - xs[0] for x in xs]

    for z in zs:
        if z == 0:
            D = z
        else:
            D = gcd(D, z)
    return D

def test():
    print(solve(13, [16 + 3 * 102485 * i for i in range(10**5)]))

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

    print(solve(X, xs))

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] = [int(x) for x in input().split()]
xs = [int(x) for x in input().split()]

xs.append(X)
xs = sorted(xs)

d = [y-x for x,y in zip(xs[:-1], xs[1:])]

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
N,X = input().split()

x_list = input().split()

x_list_X  = [abs(int(i)-int(X)) for i in x_list]

# N,Mの最大公約数　
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)

print(reduce(gcd, x_list_X))

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())
a = list(map(int, input().split()))

if n == 1:
  print(abs(x-a[0]))
  exit()
  
b = []
for i in range(1,n):
  b.append(a[i]-a[i-1])
b.append(abs(a[0]-x))
print(gcd_list(b))

Submission status: Accepted

Solution code:
import numpy as np

N, X = list(map(int, input().split()))
x = np.array(list(map(int, input().split())))
x = np.abs(X - x)

for i in range(N-1):
    a, b = x[i:i+2]
    while b > 0:
        a, b = b, a % b
    x[i+1] = a

print(x[-1])

Submission status: Accepted

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

for i in range(len(x)-1):
    a, b = x[i], x[i+1]
    while b > 0:
        a, b = b, a % b
    x[i+1] = a

print(x[-1])

Submission status: Accepted

Solution code:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))


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


print(reduce(gcd, [abs(l-X) for l in loc]))

Submission status: Accepted

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


def main():
    n, y = map(int, input().split())
    xs = list(map(int, input().split()))
    res = abs(y - xs[0])
    for x in xs[1:]:
        res = gcd(res, abs(y - x))
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a==b:
        return b
    elif b==1:
        return 1
    elif a%b == 0:
        return b
    else:
        return gcd(b,a%b)
    
N,X = map(int,input().split())
x = list(map(int,input().split()))

dist = []

for i in range(N):
    dist.append(abs(X-x[i]))
dist.sort
if len(dist) == 1:
    temp = dist[0]
else:
    temp = gcd(dist[1],dist[0])
for i in range(2,N):
    temp = gcd(dist[i],temp)
    
print(temp)

Submission status: Accepted

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

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

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

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

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())

clist = [X]
diff = []

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

clist.sort(reverse = False)

for s in range(1, N+1):
    diff.append(clist[s] - clist[s-1])

print(gcd_list(diff))

Submission status: Accepted

Solution code:
import fractions as math

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

x_0 = [x_- x_min for x_ in x]

gcd = x_0[0]
for x_0_ in x_0:
    gcd = math.gcd(gcd,x_0_)

print(gcd)

Submission status: Accepted

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

ans = distance[0]

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

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

print(ans)

Submission status: Accepted

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

for i in range(N):
	x[i] -= X
if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	print(abs(a))

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
import functools
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff_list = []

for i in range(N):
    diff_list.append(max(x[i], X) - min(x[i], X))
gcd = functools.reduce(fractions.gcd, diff_list)
print(gcd)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
city = list(map(int, input().split()))
D = []

for i in range(n):
    dis = abs(x - city[i])
    D.append(dis)
    
def gdc(x, y):
    if x%y == 0:
        return y
    x, y = y, x%y
    return gdc(x, y)

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

print(D[-1])

Submission status: Accepted

Solution code:
import numpy as np
import math
import itertools

# 距離の最大公約数を求める

def factorize(M):
    P = []
    F = []
    for m in range(2, int(math.sqrt(M))+1):
        n = 0
        while M % m == 0:
            M/= m
            n +=1
        if n != 0:
            P.append(m)
            F.append(n)
    if M != 1:
        P.append(M)
        F.append(1)
    return P,F

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

dN = np.abs(np.array(xN) - X)
P,F = factorize(np.min(dN))

M = []
for F_ in itertools.product(*list(map(lambda f:range(f+1), F))):
    m = 1
    for p,f in zip(P,F_):
        m *= int(pow(p,f))
    if np.all(np.mod(dN, m) == 0):
        M.append(m)

print(max(M))

Submission status: Accepted

Solution code:
####################
def pri(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X
####################


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

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

x.sort()

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

d.sort()

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

m = d[0]
P = pri(d[0])
for i in range(1,len(d)):
  if d[i] % m != 0:
    t = pri(d[i])
    m = 1
    for j in list(P):
      if j in t:
        P[j] = min(P[j], t[j])
        m *= j ** P[j]
      else:
        del P[j]
print(m)

Submission status: Accepted

Solution code:
####################
def pri(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X
####################


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

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

x.sort()

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

d.sort()

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

m = d[0]
P = pri(d[0])

for i in range(1,len(d)):
  if d[i] % m != 0:
    t = pri(d[i])
    m = 1
    for j in list(P):
      if j in t:
        P[j] = min(P[j], t[j])
        m *= j ** P[j]
      else:
        del P[j]

print(int(m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

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

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

delta = [abs(X-i) for i in x]
print(reduce(gcd, delta))

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
X = list(map(int, input().split()))
X.sort(reverse=True)
D = []

for i in range(len(X)):
    dist = abs(x - X[i])
    D.append(dist)

def gcd(i, j):
    while j != 0:
        i, j = j, i % j
    return i

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

print(D[-1])

Submission status: Accepted

Solution code:
# coding: utf8

from functools import reduce

def gcda(x, y):
    while y:
        x, y = y, x % y
    return x

def gcd(*numbers):
    return reduce(gcda, numbers)


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


if __name__ == "__main__":
    n, x = read_int_n()
    y = read_int_n()
    y.append(x)

    y.sort()
    w = [y[i] - y[i-1] for i in range(1, len(y))]
    print(gcd(*w))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_greatest_common_divisor(n1, n2) :
    # euclidean_algorithm
    if (n2 == 0) :
        return n1
    return get_greatest_common_divisor(n2, n1 % n2)


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

n2 = abs(locations[0] - X)
for i in range(len(locations),1,-1) :
    n1 = abs(locations[i-1] - X)
    n2 = get_greatest_common_divisor(n1,n2)

print(n2)
# locationsの最大公約数が分かればいいはず。

Submission status: Accepted

Solution code:
from fractions import gcd


def gcd_array(a):
    gg = gcd(a[0],a[1])

    for i in range(2, len(a)):
        gg = gcd(gg, a[i])
    return gg


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

b = [abs(int(k) - x) for k in input().split()]

if len(b) == 1:
    print(b[0])
else:
    print(gcd_array(b))

Submission status: Accepted

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

def gcd(n,m):
	if n%m==0:
		return m;
	else:
		return gcd(m,n%m);

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

N, X = [int(x) for x in input().split()]
x_list = input().split()
x_list = list(map(int, x_list))
x_list = list(map(lambda x: abs(X - x), x_list))
print(gcd(*x_list))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

N, X = map(int,input().split()) 
nums=list(map(int,input().split()))
nums=list(map(lambda i: abs(i - X),nums))
 
D = reduce(gcd, nums)
print(D)

Submission status: Accepted

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

Submission status: Accepted

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

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

gcd=diffx[0]
for i in range(1,N):
    gcd=euclid(diffx[i],gcd)
print(gcd)

Submission status: Accepted

Solution code:
import math

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

A = [x - S for x in X]

def lcd(a,b):
    a = abs(a)
    b = abs(b)
    a,b = min(a,b), max(a,b)
    if a == 0:
        return b
    return lcd(b%a, a)


ret = A[0]
for a in A:
    ret = lcd(ret, a)

print(ret)

Submission status: Accepted

Solution code:
import math

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

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

ans = abs(t[0]-x)
for i in range(1,len(t)):
    t[i] = abs(t[i]-x)
    ans = gcd(ans,t[i])

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,x = map(int, input().split())
xl = list(map(int, input().split()))

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

xl.append(x)
xl.sort()
res = None
for i in range(n):
    d = xl[i+1] - xl[i]
    if res is None:
        res = d
    else:
        res = gcd(res, d)
print(res)

Submission status: Accepted

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

def kouyaku(a,b):
    aa = max(a,b)
    bb = min(a,b)
    if bb == 0:
        return aa
    else:
        return kouyaku(bb,aa%bb)

res = 0
for i in P:
    if res:
        res = kouyaku(res, abs(X - i))
    else:
        res = abs(X - i)

print(res)

Submission status: Accepted

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


def main():
    N, x = map(int, input().split())
    y = list(map(int, input().split()))
    y = [abs(i - x) for i in y]
    ans = y[0]
    for i in y[1:]:
        ans = gcd(i, ans)

    print(ans)

main()

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def inpl(): return [int(i) for i in input().split()]

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

Submission status: Accepted

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

l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))

x = reduce(gcd,l)
print(x)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce

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

N,X=map(int,input().split(" "))
x=np.array(list(map(int, input().split(' '))))
y=abs(x-X)
print(reduce(euclid,y))

Submission status: Accepted

Solution code:
from fractions import gcd


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

diffs = [abs(x - X) for x in xs]

tmp = diffs[0]
for i in range(1, N):
    tmp = gcd(tmp, diffs[i])
print(tmp)

Submission status: Accepted

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

def gcd(x,y):
    if y==0:
      return x
    else:
      return gcd(y,x%y) 
    
if n==1:
  x=l[0]
else:
  x=gcd(l[0],l[1])
  if n>2:
    for i in range(2,n):
      x=gcd(x,l[i])
print(x)

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.append(X)
x.sort()
array = []
for i in range(N):
    array.append(x[i+1]-x[i])

if len(array) > 1:
    result = gcd(array[0], array[1])
    for i in range(2, len(array)):
        result = gcd(result, array[i])
else:
    result = array[0]
    
print(result)

Submission status: Accepted

Solution code:
from fractions import gcd
n,x=map(int, input().split())
x = list(map(int, input().split())) + [x]
x.sort()
ret = x[1] - x[0]

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

print(ret)

Submission status: Accepted

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

g = abs(X - src[0])
for a,b in zip(src,src[1:]):
    d = b-a
    g = gcd(g, d)
print(g)

Submission status: Accepted

Solution code:
import sys
fin = sys.stdin.readline


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

N, X = [int(elem) for elem in fin().split()]
x_list = [int(elem) for elem in fin().split()]

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

print(D)

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 - x[i])

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

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

print(d)

Submission status: Accepted

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

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

s=abs(A[0]-X)
for i in range(1,N):
    s=gcd(s,abs(A[i]-X))

print(s)

Submission status: Accepted

Solution code:
def gcd(g, s):
    while g % s != 0:
        s, g = sorted([g,s])
        g = g % s
    return s

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

    for i in range(n):
        X[i] -= x
        if X[i] < 0:
            X[i] *= -1

    m = X[0]
    for c in X[1:]:
        m = gcd(c,m)

    print(m)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import functools
def gcd( a, b ):
    while b != 0:
        a, b = b,a%b
    return a
n,x=map(int,input().split())
l = [abs(int(i) - x) for i in input().split()]
print(functools.reduce(gcd,l))

Submission status: Accepted

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

n, x = (int(i) for i in input().split(" "))
xn = (int(i) for i in input().split(" "))

nums = [abs(xi-x) for xi in xn]

b = nums[0]
for v in nums[1:]:
    b = gcd(b,v)

print(b)

Submission status: Accepted

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

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

s = []
for i in xx:
    a = x - i
    if a < 0:
        s.append(-a)
    else:
        s.append(a)

import fractions
v = s[0]
for b in s[1:]:
    v = fractions.gcd(b, v)
print v

Submission status: Accepted

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

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

s = []
for i in xx:
    a = x - i
    if a < 0:
        s.append(-a)
    else:
        s.append(a)

import fractions
v = s[0]
for b in s[1:]:
    v = fractions.gcd(b, v)
print v

Submission status: Accepted

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


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

X.append(St)
X = sorted(X)

del_X = []
for i in range(N):
    del_X.append(X[i+1] - X[i])
del_X = sorted(list(set(del_X)))

# print(X)
# print(del_X)

for i in range(len(del_X)):
    if i == 0:
        tmp = gcd(del_X[i],0)
    else:
        tmp = gcd(tmp, del_X[i])
print(tmp)

Submission status: Accepted

Solution code:
def gcd(a, b):
    """
    最大公約数
    """
    if b > a:
        a, b = b, a
    c = a % b
    return b if c == 0 else gcd(b, c)


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

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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


def m():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    b = [0] * n

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

    tmp = b[0]
    for i in range(n):
        tmp = gcd(tmp, b[i])

    return tmp

print(m())

Submission status: Accepted

Solution code:
import sys
from functools import reduce
from fractions import gcd


def main():
    n, x = list(map(int, input().split()))
    values = list(map(int, input().split()))
    values.append(x)
    values.sort()
    v = [values[i + 1] - values[i] for i in range(len(values) - 1)]
    res = v[0]
    print(reduce(gcd, v[1:], v[0]))


if __name__ == "__main__":
    main()

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 = [abs(int(i) - X) for i in input().split()]

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

Submission status: Accepted

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

N ,X = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
abs_xlist = list(map(lambda x:abs(X - x), xlist))
abs_xlist.sort()
ans = abs_xlist[0]

for i in range(N):
    num = gcd(abs_xlist[i],ans)
    ans = min(num,ans)
print(ans)

Submission status: Accepted

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

N ,X = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
abs_xlist = list(map(lambda x:abs(X - x), xlist))
abs_xlist.sort()
ans = abs_xlist[0]

for i in range(N):
    if abs_xlist[i] % ans != 0:
        num = gcd(abs_xlist[i],ans)
        ans = min(num,ans)
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
def myabs(i):
    return abs(i-X)
xlis = list(map(myabs, map(int, input().split())))


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

res = xlis[0]
for i in xlis:
    if i%res == 0:
        continue
    res = gcd(i,res)

print(res)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
def myabs(i):
    return abs(i-X)
xlis = list(map(myabs, map(int, input().split())))

from fractions import gcd

res = xlis[0]
for i in xlis:
    if i%res == 0:
        continue
    res = gcd(i,res)

print(res)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
def myabs(i):
    return abs(i-X)
xlis = list(map(myabs, map(int, input().split())))

from fractions import gcd

res = xlis[0]
for i in xlis:
    res = gcd(i,res)

print(res)

Submission status: Accepted

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


def main():
    N, X = map(int, input().split())
    x = [abs(int(i) - X) for i in input().split()] 

    y = x[0]
    for i in range(N):
        if x[i]%y == 0:
            continue
        y = gcd(y, x[i])
    print(y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
y=list(map(int,input().split()))
	
bet=[] # length from X to y[i]
for i in range(N):
	bet.append(abs(y[i]-X))
bet.append(0)
bet.sort()

#length from bet to bet
bet2=[]
for i in range(len(bet)-1):
	if 	bet[i+1] != bet[i]:
		bet2.append(bet[i+1]-bet[i])
bet2.sort()

#delete same
key=bet2[0]
keylen=[key]
i=0
while i < len(bet2):
	if bet2 [i]!=key:
		keylen.append(bet2[i])
		key=bet2[i]
	else:
		i+=1


#take out multiple
def multiple(num,k):
	if num %k==0:
		return k
	else:
		return multiple(k,num%k)

while len(keylen) != 1:
	mult=[]
	for i in keylen:
		for j in keylen[keylen.index(i)+1:]:
			if j % i != 0:
				mult.append(multiple(i,j))
			else:
				keylen.remove(j)
	keylen.extend(mult)
	keylen.sort()

print(keylen[0])

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 = [abs(X-int(i)) for i in input().split()]
g = x[0]
for i in range(1,n):
    g = gcd(g,x[i])
print(g)

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(nums):
    return reduce(gcd, nums)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff = [abs(xi - X) for xi in x]
print(gcd_list(diff))