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(int, input().split()))
rec = set()
for i in range(n):
    rec.add(abs(x[i] - X))

rec = sorted(list(rec))


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


num = rec[0]
for k in range(1, len(rec)):
    num = gcd(num, rec[k])


print(num)

Submission status: Accepted

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

N, X = map(int, raw_input().split())
xs = map(int, raw_input().split())
gc = map(lambda x: abs(x - X), xs)
print reduce(gcd, gc)

Submission status: Accepted

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

        a = b
        b = amari
    return(a)


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

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

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

print(tmp)

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a, a)
n,x = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
    l[i] -= x
    l[i] = abs(l[i])
ans = []
if len(l) == 1:
    ans.append(l[0])
while len(ans) != 1:
    ans = []
    for i in range(1,len(l)):
        ans.append(gcd(l[i], l[i-1]))
    ans = list(set(ans))
    l = []
    for i in ans:
        l.append(i)
print(ans[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())
k = [abs(int(x) - X) for x in input().split()] # リスト内包表記で入力の受け取り
a = k[0]
for i in range(1,N):
    a = gcd(a,k[i])
print(str(a))

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

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

ans = dist[0]

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

print(ans)

Submission status: Accepted

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

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

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

    ans = 10**9+1
    for i in range(len(diffs)-1):
        ans = min(fractions.gcd(diffs[i], diffs[i+1]), ans)
    print(ans)

if __name__ == "__main__":
    main4()

Submission status: Accepted

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

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

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

ans = diff[0]

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

print(ans)

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()))
for i in range(n):
    xlist[i] = abs(xlist[i]-x)
    
if len(xlist)==1:
    print(xlist[0])
else:
    maxgcd = gcd(xlist[0], xlist[1])
    for i in range(2,n):
        maxgcd = gcd(maxgcd, xlist[i])
    print(maxgcd)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)

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

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

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

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

# li = [i for i in li if i]
# li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	ans = li[0]
	for i in range(1,N):
		ans = gcd(ans, li[i])
	print(ans)

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

Submission status: Accepted

Solution code:
#reduce(func, list)
#複数の要素を 1 つにまとめたいときに使う．
#具体的には，配列の先頭から 2 つの要素を取り出して処理を行い，
#次はその結果とその次の要素に処理を行う，ということを繰り返す．
from fractions import gcd
from functools import reduce
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = reduce(gcd, [abs(x-a[i]) for i in range(n)])
print(ans)

Submission status: Accepted

Solution code:
def GCD(a,b): 
  if a<b:
    a,b = b,a

  r = a % b
  
  while r!=0:
    a = b
    b = r
    r = a % b
 
  return b

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

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

ans = T[0]
for i in range(1,N):
  ans = GCD(ans, T[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 solve(lis,x):
    ans=abs(lis[0]-x)
    lis=[abs(c-x) for c in lis]
    for x in lis:
        if x!=0:
            ans=gcd(ans,x)
    return ans 
n,x=map(int,input().split())
l=list(map(int,input().split()))
print(solve(l,x))

Submission status: Accepted

Solution code:
#abc109c
from fractions import gcd

N,X=map(int,raw_input().split())
x=map(int,raw_input().split())
y=[]
for i in xrange(N):
 y.append(abs(X-x[i]))
print reduce(gcd,y)

Submission status: Accepted

Solution code:
def gcd(a,b):
        while b:
            a,b=b,a%b
        return a
def solve(lis,x):
    if len(lis)==1:
        return abs(lis[0]-x)
    lis=[abs(c-x) for c in lis]
    ans=gcd(lis[0],lis[1])
    for x in lis[2:]:
        if x!=0:
            ans=gcd(ans,x)
    return ans 
n,x=map(int,input().split())
l=list(map(int,input().split()))
print(solve(l,x))

Submission status: Accepted

Solution code:
"""
C - Skip
Xを含めた与えられた数列をソートする
最小値を基準０にする
隣同士の差を取る
数列の最大公約数を求める
"""

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

numbers = [X]
for part in input().split():
    numbers.append(int(part))

numbers.sort()

# 最小値を基準0とする（ノーマライズ）
min_num = min(numbers)
normal_numbers = []
for num in numbers:
    normal_numbers.append(num - min_num)

# 隣との距離を出す
dist_numbers = []
for i in range(1, len(normal_numbers)):
    # 重複なしで隣との距離を数える
    dist_temp = normal_numbers[i] - normal_numbers[i-1]
    if dist_temp not in dist_numbers:
        dist_numbers.append(dist_temp)

# 最大公約数を求める
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def gcd_list(numbers):
    if len(numbers) == 1:
        return numbers[0]
    elif len(numbers) == 2: 
        return gcd(numbers[0], numbers[1])
    else:
        return gcd(numbers[0], gcd_list(numbers[1:]))

print(gcd_list(dist_numbers))

Submission status: Accepted

Solution code:
from functools import reduce

def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]
    if not x in points:
        points.append(x)

    buf = [abs(points[i + 1] - points[i]) for i in range(len(points) - 1)]
    print(reduce(lambda a,b: euclid(a, b), buf))

Submission status: Accepted

Solution code:
from functools import reduce

def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]

    buf = [abs(p - x) for p in points]
    print(reduce(lambda a,b: euclid(a, b), buf))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

print(reduce(gcd, dist))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

print(reduce(gcd, dist))

Submission status: Accepted

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

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

    return a

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

N, X = map(int, input().split(' '))
city = np.array(list(map(int, input().split(' '))))

city -= X
print(abs(multi_gcd(*city)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
X=int(input().split()[1]);print(reduce(gcd,map(lambda x:abs(int(x)-X),input().split())))

Submission status: Accepted

Solution code:
from functools import reduce
def g(a,b):
  while b:a,b=b,a%b
  return a
X=int(input().split()[1]);print(reduce(g,map(lambda x:abs(int(x)-X),input().split())))

Submission status: Accepted

Solution code:
from functools import reduce
def g(a,b):
  while b:a,b=b,a%b
  return a
def f(x):return reduce(g,x)
X=int(input().split()[1]);print(f(map(lambda x:abs(int(x)-X),input().split())))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N,x0 = map(int,input().split())
print(abs(reduce(gcd, map(lambda s: int(s)-x0, input().split()))))

Submission status: Accepted

Solution code:
import fractions

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

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

dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

max_common_value = dist_list.pop(0)

for dist in dist_list:
    # 今までのDと次の都市の距離との最大公約数を見つける
    max_common_value = fractions.gcd(max_common_value, dist)

print(max_common_value)

Submission status: Accepted

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

ans = 0
for i in x:
    ans = gcd(ans, abs(i - X))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,X = list(map(int,input().split()))
x = np.array(list(map(int,input().split())))
#distance from point"X"
Xar = np.array([X]*N)
d = abs(x-Xar)
def EA(a,b):
    if a%b ==0:
        return b
    else:
        return EA(b,a%b)
if len(x)==1:
    ans = d[0]
else:
    ans = EA(d[0],d[1])
    for i in range(N):
        ans = EA(ans,d[i])
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n, x = map(int, input().split())
y = [abs(int(v) - x) for v in input().split()]
g = y[0] if len(y) == 1 else reduce(gcd, y)
print(g)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def gcd(p):
	ret = p[0]
	def f(s,t):
		return f(t,s%t) if t else s
	for d in p:
		ret = f(ret,d)
	return ret
n,x=map(int,input().split())
print(gcd(list(map(lambda t:abs(int(t)-x),input().split()))))

Submission status: Accepted

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

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


if n==1:
    print(first_distance[0])
else:
    element = gcd(first_distance[0], first_distance[1])
    if n==2:print(element)
    else:
        for i in range(2,n):
            element=gcd(element,first_distance[i])
        print(element)

Submission status: Accepted

Solution code:
# from math import gcd
def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 0:
        return x
    return gcd(y, x % y)


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

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:
import fractions
n,x=map(int,input().split())
l=list(map(int,input().split()))
m=[]
for i in l:
  m.append(abs(i-x))
n=m.pop(0)
for j in m:
  n=fractions.gcd(n,j)
print(n)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]

x_list.sort()

current_gcd = 0
for i in range(0, n):
    gap = abs(start - x_list[i])
    current_gcd = fractions.gcd(current_gcd, gap)

print(current_gcd)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from fractions import gcd

# スペース区切りの整数の入力
N, X = map(int, input().split())
pos = [int(x.strip()) for x in input().split()]

# 一番近い場所を検索
tikai = [i - X for i in pos]
kyori = list(map(abs,tikai))

a = kyori[0]
for xi in kyori[1:]:
    a = gcd(a, xi)
print(a)

Submission status: Accepted

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

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())
x.sort()
	
for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		break
if len(x) == N:
	x.append(X)
diff = []
for i in range(N):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 1):
	res = gcd(res, diff[i + 1])
print res

Submission status: Accepted

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

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

city.append(x)
city.sort()

dist = []
for i in range(len(city)-1):
    dist.append(abs(city[i]-city[i+1]))

if len(dist) < 2:
    min_dist = dist[0]
else:
    min_dist = 0
    for i in range(len(dist)-1):
        if min_dist == 0:
            min_dist = gcd(dist[i], dist[i+1])
        else:
            min_dist = min(min_dist, gcd(dist[i], dist[i+1]))

print(min_dist)

Submission status: Accepted

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

x_list.sort()
def gcd(a, b):
    if a >= b:
        return a if b == 0 else gcd(b, a % b)
    else:
        return gcd(b, a)


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

print(D)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, x))

Submission status: Accepted

Solution code:
N, X = map(int,input().split(" "))
x = map(int, input().split(" "))
d = [abs(i-X) for i in x]
d_min = min(d)
def func(d_min,d):
  for i in range(d_min+1,0,-1):
    a=True
    for k in d:
      if k%i == 0:
        continue
      else:
        a = False
        break
    if a:
      return i
print(func(d_min,d))

Submission status: Accepted

Solution code:

import numpy as np
from functools import reduce
import fractions

def main():
    N, X = map(int, input().split())
    x = np.absolute([int(i)-X for i in input().split()])
    if N == 1:
        print(x[0])
    else:
        print(reduce(fractions.gcd, x))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

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

dic = []

for i in range(len(x) - 1):
    tmp = x[i + 1] - x[i]
    if tmp not in dic:
        dic.append(tmp)

ans = max(dic)

for i in range(len(dic) - 1):
    ans = min(ans, fractions.gcd(dic[i], dic[i + 1]))

print(ans)

Submission status: Accepted

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

n,x=map(int,input().split())
*l,=map(int,input().split())
*y,=map(lambda a:abs(a-x),l)
print(reduce(gcd,y))

Submission status: Accepted

Solution code:

import numpy as np
from functools import reduce
import fractions

def main():
    N, X = map(int, input().split())
    x = np.absolute(np.asarray([int(i) for i in input().split()]) - X)
    if N == 1:
        print(x[0])
    else:
        print(reduce(fractions.gcd, x))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

lis = list(map(int,input().split()))
diffs = []
for i in range(n):
    diff = abs(lis[i]-x)
    diffs.append(diff)


if len(diffs) > 1:
    com = fractions.gcd(diffs[0],diffs[1])
    for i in range(len(diffs)-2):
        com = fractions.gcd(com, diffs[i+2])
else:
    com = diffs[0]

print(com)

Submission status: Accepted

Solution code:

import numpy as np
import fractions

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = fractions.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:# x >= y とする
        x, y = y, x
    r = x % y
    res = y if r == 0 else gcd(y, r) 
    return res

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

g = x2[0]
for i in x2:
    g = gcd(g, i)
print(g)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
N,X =[int(i) for i in input().split()]
c = [int(i) for i in input().split()]
 
for i in range(N):
    c[i] = abs(c[i] - X)
 
print(gcd_list(c))

Submission status: Accepted

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

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


while len(diff) > 1:
    a, b = diff.pop(), diff.pop()
    diff.append(gcd(a, b))

print(diff[0])

Submission status: Accepted

Solution code:
def c_skip(N, X, Pos):
    from fractions import gcd
    from functools import reduce
    # 座標Xから各都市への距離を求め、それらの最大公約数が解
    ans = reduce(gcd, [abs(X - x) for x in Pos])
    return ans

N, X = [int(i) for i in input().split()]
Pos = [int(i) for i in input().split()]
print(c_skip(N, X, Pos))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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


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

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

print(gcd_list(c))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions
from functools import reduce

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

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

absList =[0] * len(toshiList)

for i in range(0,len(toshiList)):
    absList[i] = abs( toshiList[i] - X)

ans = reduce(fractions.gcd,absList)
    
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

R = reduce(fractions.gcd, [abs(X - x) for x in XL])

print(R)

Submission status: Accepted

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

field = [int(i) for i in input().split()]

diff = list(map(lambda a:abs(a-x),field))

def gcd(x,y):
    # print(x,y)
    if x < y:
        x,y = y,x

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

ans = diff[0]


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

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

for i in range(n):
  y.append(abs(x-z[i]))

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
aa = list(map(int,input().split()))
 
bb = [abs(a-m) for a in aa]


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

    
ans = bb[0]
if len(aa) == 1:
    print(abs(aa[0]-m))
else:
    for b in bb:
        ans = gcd(ans,b)
    print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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


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

print(abs(gcd_list(x)))

Submission status: Accepted

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

D=[]

for i in range(N):
    D.append(abs(X-Z[i]))
    
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
res = D[0]

for j in range(1, N):
    res = gcd(res, D[j])

print(res)

Submission status: Accepted

Solution code:
from fractions import gcd
def fun():
    nx = input()
    N, X = nx.split(' ')
    N = int(N)
    X = int(X)
    cities = [int(c) for c in input().split(' ')]
    cities.append(X)
    x = sorted(cities)
    nx = x[1:]
    dist = [nn - x[i] for i, nn in enumerate(nx)]
    if N==1:
        print(dist[0])
        return
    min_gcd = 10000000000
    for i, d in enumerate(dist[:-1]):
        dp = dist[i+1]
        gc = gcd(d, dp)
        if gc < min_gcd:
            min_gcd = gc
    print(min_gcd)

fun()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions
 
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
y=[]
 
i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()
 
y=list(set(y))
m=len(y)
z=y[0]
i=0
while i < m:
    z=fractions.gcd(z,y[i])
    i+=1
 
print(z)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
pos=list(map(int,input().split()))
pos2=[abs(p-x) for p in pos]
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
 
        return divisor_list

if n==1: ans=pos2[0]
else:
    minpos= min(pos2)
    divs=make_divisor_list(minpos)[::-1]
    if divs[0]==1:ans=1
    else:
        for j in divs:
            if all(x%j==0 for x in pos2):
                ans=j
                break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import fractions
from functools import reduce
N,X = map(int,input().rstrip().split())
x = []
x = list(map(int,input().rstrip().split()))
x.append(X)
x.sort()


mini = []
for i in range(len(x)-1):
	mini.append(x[i+1] - x[i])
print(reduce(fractions.gcd, mini))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
aa = list(map(int,input().split()))
 
bb = [abs(a-m) for a in aa]

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
    
if len(aa) == 1:
    print(abs(aa[0]-m))
else:
    while len(bb) > 1:
        a, b = bb.pop(), bb.pop()
        bb.append(gcd(a,b))
    print(bb[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd3(x,y):
    if x>=y:
        if x%y==0:
            return y
        else:
            return gcd3(y,x%y)
    else:
        if y%x==0:
            return x
        else:
            return gcd3(x,y%x)
def gcd2(x4):
    if len(x4)>2:
        return gcd3(gcd2(x4[:len(x4)//2]),gcd2(x4[len(x4)//2:]))
    elif len(x4) ==2:
        return gcd3(x4[0],x4[1])
    else:
        return x4[0]
N, X = map(int,input().split())
x=[int(i) for i in input().split()]
x.append(X)
x3=[]
for i in range(len(x)-1):
    x3.append(abs(x[i+1]-x[i]))
print(gcd2(x3))

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=sorted(map(lambda x:abs(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if x[0]%i:continue
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break

Submission status: Accepted

Solution code:
from fractions import gcd

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

res = x[0]

for i in x:
    res = gcd(res,i)

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions
import numpy as np
 
N,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
 
x=np.array(x)
 
y=x[1:]-x[:-1]
 
y.sort()
y=list(set(y))
z=y[0]
m=len(y)
i=0
while i < m:
    z=fractions.gcd(z,y[i])
    i+=1
 
print(z)

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())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
cities.sort()
D=cities[0]
for i in range(N):
  D=gcd(D,cities[i])
print(D)

Submission status: Accepted

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b%a,a)
if n == 1:
    val = abs(lis[0]-x)
    print val
    exit()
val = 0
#print lis
for i in xrange(n):
    lis[i] -= x
    val = gcd(abs(lis[i]), val)
print val

Submission status: Accepted

Solution code:
import functools
import fractions
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
co = 0
for i in range(a[0]):
	c.append(abs(b[i]-a[1]))
	if b[i]-a[1] > 0 and co == 0:
		c.insert(i,0)
		co += 1
if co == 0:
	c.append(0)

for i in range(len(c)-1):
	d.append(abs(c[i+1]-c[i]))
print(functools.reduce(fractions.gcd, d))

Submission status: Accepted

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

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
if len(b) == 2:
    print(b[1] - b[0])
    exit(0)
c = [abs(a - x) for a in b]


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


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

Submission status: Accepted

Solution code:
import fractions
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

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

Submission status: Accepted

Solution code:
from functools import reduce
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	def gcd(a,b):
		while b>0:
			a,b=b,a%b
		return a
	print(reduce(gcd,LL))

Submission status: Accepted

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
                    break
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1       
        print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(reduce(gcd, sa))

Submission status: Accepted

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

Submission status: Accepted

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

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

def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(gcd(c2 - c1, c3 - c2))
        return min(gcds)

print(get_res(cities))