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 numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
d=[0]*n
for i in range(n):
    d[i]=x[i+1]-x[i]
res=d[0]
for i in range(1,n):
    res=math.gcd(res,d[i])
print(res)

Submission status: Accepted

Solution code:
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
def euclid(a,b):
    if a % b == 0:
        return b
    else:
        return euclid(b, a%b)

now = abs(x[0] -x[1])
for i in range(1, len(x)-2):
    r = euclid(now, abs(x[i] - x[i+1]))
    if r < now:
        now = r
r = euclid(now, abs(x[0] - x[-1]))
if r < now:
    now = r
print(now)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
from functools import reduce


# 最大公約数（リスト引数）
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


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

# 座標XからDずつ移動してぴったりxkを訪れられる
# ⇄ |X - xk|がDで割り切れる
# ⇄ Dは|X-x1|,|X-x2|,...,|X-xN|の公約数
# つまりDの最大値は、|X-x1|,|X-x2|,...,|X-xN|の最大公約数

nums = [abs(X - xk) for xk in x]
ans = gcd_list(nums)
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def li(): return map(int,sys.stdin.readline().rstrip().split())
def lf(): return map(float,sys.stdin.readline().rstrip().split())
def ls(): return sys.stdin.readline().rstrip().split()

n, x = li()
p = list(li())
gcd = abs(x-p[0])
for i in range(n):
    gcd = math.gcd(gcd, abs(x-p[i]))

print(gcd)

Submission status: Accepted

Solution code:
def gcd(p,q):
    if p%q==0: return q
    else: return gcd(q,p%q)
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = [abs(x-i) for i in a]
ans = b[0]
for i in range(1,n):
    ans = min(ans,gcd(ans,b[i]))
print(ans)

Submission status: Accepted

Solution code:
import sys
from math import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, X = in_nn()
    x = in_nl()
    x += [X]
    x.sort()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce


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

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

    
    list_s = []
    for i in range(n):
        list_s.append(abs(x_list[i]-x))
        
    ans = gcd_list(list_s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_c
# Xを中心にしたときの最大公約数かな
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


from functools import reduce
from math import gcd

N, zero = ints()
X = [abs(x - zero) for x in ints()]
# if N == 1:
#     exit(X[0] - zero)
print(reduce(gcd, X))

Submission status: Accepted

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

import numpy as np
import fractions

a = list(set(abs(np.array(x_list) - X)))
ans = a[0]
for i in range(1, len(a)):
    ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
N,X = map(int,input().split())
g = None
for x in map(int,input().split()):
    if g == None:
        g = x-X
    else:
        g = gcd(g,x-X)
print(abs(g))

Submission status: Accepted

Solution code:
import math
from functools import reduce


def gcd_list(l):
    return reduce(math.gcd, l)


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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

N, X = list(map(int, input().split()))
 
x = list(map(int, input().split()))
x.append(X)
x.sort()
 
res = [abs(x[i+1]-x[i]) for i in range(len(x)-1)]
print(gcd(*res))

Submission status: Accepted

Solution code:
from math import*
N,x=map(int,input().split())
*X,=map(int,input().split())
ans=abs(X[0]-x)
now=X[0]
for i in X[1:]:
    ans=gcd(ans,abs(i-now))
    now=i

print(ans)

Submission status: Accepted

Solution code:
#ABC109-C
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)

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

x.append(X)
x.sort()

kosa = []

for i in range(1,n+1):
    k = (x[i]-x[i-1])
    kosa.append(k)
    
print(gcd(*kosa))

Submission status: Accepted

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


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

    X = sorted(X)

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

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

    ans = 0
    if (len(diff) == 1):
        print(diff[0])
        exit()
    else:
        ans = gcd(diff[0], diff[1])
        for i in range(2, len(diff)):
            ans = gcd(ans, diff[i])

        print(ans)

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

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

print(ans)

Submission status: Accepted

Solution code:

import numpy as np

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

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

s.append(x)

s.sort()

l = set([])

for i in range(len(s)-1):
    l.add(s[i+1]-s[i])
    
l = list(l)
    
print(np.gcd.reduce(l))

Submission status: Accepted

Solution code:
import math


def main():
    n, s = map(int, input().split())
    xs = sorted(list(map(int, input().split())))

    for i in range(n):
        xs[i] = abs(xs[i] - s)

    for i in range(1, n):
        xs[i] = math.gcd(xs[i], xs[i-1])

    print(xs[n-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

import math
for i in range(1,n):
  x[i] = math.gcd(x[i],x[i-1])

print(x[n-1])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import math
from functools import reduce

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

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


n, s = map(int, readline().split())
x = [v-s for v in list(map(int, readline().split()))]

print(abs(gcd(*x)))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

N,X=map(int,input().split())
A=list(map(int,input().split()))
B=[abs(a-X) for a in A]
print(gcd(*B))

Submission status: Accepted

Solution code:
import math
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=abs(l[0]-x)
for m in l:
  d2=math.gcd(d,abs(m-x))
  d=min(d,d2)
print(d)

Submission status: Accepted

Solution code:
import numpy as np
import math
from functools import reduce
N,X,*x = map(int,open(0).read().split())
print(reduce(math.gcd,abs(X - np.array(sorted(x)))))

Submission status: Accepted

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

N,X,*x = map(int,open(0).read().split())
x.sort()
nx = np.array(x)
dif_nx = abs(X - nx)
print(reduce(math.gcd,dif_nx))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353


#############
# Main Code #
#############

N, X = getNM()
A = getList()

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

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

Submission status: Accepted

Solution code:
from math import gcd
n, x = map(int, input().split())
city = list(map(int, input().split()))
if x not in city:
    city.append(x)
city.sort(reverse=True)
for i in range(len(city) - 1):
    city[i] -= city[i + 1]
ans = city[0]
for i in range(len(city) - 1):
    ans = gcd(ans, city[i])
print(ans)

Submission status: Accepted

Solution code:
import math

n, x = map(int, input().split())
X = sorted(list(map(int, input().split())))
dis = [0] * (n-1)

xdis = 0
for i in range(n-1):
    dis[i] = X[i+1] - X[i]
    if X[i] <= x <= X[i+1]:
        xdis = min(abs(x-X[i]), abs(X[i+1]-x))

if n == 1:
    print(abs(X[0]-x))
    exit()
        
reg = xdis

for i in range(n-1):
    reg = math.gcd(reg, dis[i])

print(reg)

Submission status: Accepted

Solution code:
import math
from functools import reduce
N, X = map(int, input().split())
x = list(map(int,input().split()))
 
for i in range(N):
    x[i] = abs(x[i]-X)
 
x = sorted(x)[::-1]
cnt = 0
 
for i in range(N):
    cnt = math.gcd(cnt, x[i])
 
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
from functools import reduce


def read():
    N, X = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, X, A


def solve(N, X, A):
    A = [a-X for a in A]
    ans = reduce(math.gcd, A)
    return abs(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
X=abs(X-x[0])
for i in range(N-1):
  X=gcd(max(X,abs(x[i+1]-x[i])),min(X,abs(x[i+1]-x[i])))
print(X)

Submission status: Accepted

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=[]
for i in c:
    d.append(abs(b-i))
print(gcd_list(d))

Submission status: Accepted

Solution code:
from math import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
m = 0
for i in range(N):
    if m == 0:
        m = x[i+1]-x[i]
    else:
        m = gcd(m, x[i+1]-x[i])
print(m)

Submission status: Accepted

Solution code:
import sys
n,x=map(int,input().split())
xlist=[abs(x-int(y)) for y in input().split()]

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

if n==1:
    print(xlist[0])
    sys.exit()

ans=0
for i in range(n-1):
    if i==0:
        ans=gcd(xlist[i],xlist[i+1])
    else:        
        ans=min(ans,gcd(xlist[i],xlist[i+1]))
print(ans)

Submission status: Accepted

Solution code:
from math import gcd

def MI():
    return map(int, input().split())

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

N, X = MI()
x = LI()
D = abs(X - x[0])

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

Submission status: Accepted

Solution code:
import math
import sys
def gcd(l: list):
    n=len(l)
    gcd=math.gcd(l[0],l[1])
    for i in range(2,n):
        gcd=math.gcd(l[i],gcd)

    return gcd

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

if n==1:
    print(abs(x_list[0]-x))
    sys.exit()


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

print(gcd(y))

Submission status: Accepted

Solution code:
import numpy as np
import math
N, X = map(int,input().split())
x = list(map(int,input().split()))
_x = N*[0]

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

if N == 1:
  print(_x[0])
  exit()
ans = math.gcd(_x[0],_x[1])
for i in range(2,N):
  ans = math.gcd(_x[i],ans)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
n, x = map(int, input().split())
x = list(map(lambda xi: abs(int(xi) - x), input().split()))
g = x[0]
for xi in x:
    g = gcd(g, xi)
print(g)

Submission status: Accepted

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

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

x.sort()

gcd = 0

for i in range(N):
    if i == 0:
        gcd = x[i+1]-x[i]
    else:
        gcd = fractions.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
print(gcd)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
n,s=map(int,input().split())
x=list(map(int,input().split()))
#print(x)

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

print(reduce(fractions.gcd,x))

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
N,X=map(int,input().split())
x=list(map(int,input().split()))
kari=[]
for i in range(N):
    kari.append(abs(x[i]-X))
ans=gcd(min(kari),max(kari))
for i in range(N):
    ans=gcd(ans,kari[i])
print(ans)

Submission status: Accepted

Solution code:
import functools
from fractions import gcd
n,x =map(int,input().split())
if n==1:
    c = abs(int(input())-x)
    print(c)
else:
    lis = list(map(int,input().split()))
    for i in range(n):
        lis[i] = abs(lis[i]-x)
    print(functools.reduce(gcd,lis))

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:
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
arr.sort()
g = abs(arr[0] - x)
for i in range(1,n):
    g = gcd(g, abs(arr[i] - x))
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
ls = list(map(int,input().split()))
ls = list(map(lambda t:abs(t-x),ls))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
print(gcdlist(ls))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

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

N, S = mi()
X = li()
ans = abs(S - X[0])
for i in range(1, N):
    ans = gcd(ans, abs(S - X[i]))

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

gcd = S[0]
for k in range(N-1):
  gcd = fractions.gcd(gcd, S[k+1])
print(gcd)

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 = list(set(x))
x.sort()
y = [x[i+1]-x[i] for i in range(len(x)-1)]

if len(x) == 1:
  print(0)
  exit()
elif len(x) == 2:
  print(abs(x[1]-x[0]))
  exit()
else:
  ans = y[0]
  for i in range(len(y)):
    ans = gcd(ans,y[i])
print(ans)

Submission status: Accepted

Solution code:
import math 
import fractions

a,b=map(int,input().split())
l=list(map(int,input().split()))
b_l = []
for i in range(a):
    b_l.append(abs(b-l[i]))
ans=b_l[0]
for j in range(1,a):
    ans = fractions.gcd(ans,b_l[j])
print(ans)

Submission status: Accepted

Solution code:
def gcd(a,b):
	if a%b==0:return b
	else:return gcd(b,a%b)
INF=10**9
ans=INF
n,X=map(int,input().split())
x=list(map(int,input().split()))
if n==1:
	print(abs(X-x[0]))
else:
	for i in range(n-1):
		tmp=gcd(abs(X-x[i]),abs(X-x[i+1]))
		ans=min(ans,tmp)
	print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

def mi():
    return map(int, input().split())

def main():
    N, X = mi()
    x = list(mi())
    y = [abs(x[i]-X) for i in range(N)]
    t = y[0]
    for i in range(N):
        t = gcd(t, y[i])
    print(t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,X = readInts() # その時点の距離からの絶対値
a = list(map(lambda x:abs(X - int(x)), input().split()))
res = 0
from fractions import gcd
for i in range(n):
    res = gcd(res,a[i])
print(res)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

# move1 = D
# move2 = -D


# D = 1のときは必ずゴールできる
ans = []
# 初期のXとそれ以外の街の差をDで割ったあまりが全て0なら訪れることができる
# つまりそれぞれの街の差を保存し、その最大公約数がDとなる
for i in range(N):
    dfe = abs(L[i] - X)
    ans.append(dfe)

ans = list(set(ans))

# reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]
# functoolsのreduceはある関数があり、それを前の計算結果と重なりを考慮しながら
# 関数に当てはめる、というアクションを繰り返す


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


# print(ans)
# print(reduce(lambda x, y: x + y, ans))
print(gcd_list(ans))

Submission status: Accepted

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

is_ok = True
# x[i] - X たちの最大公約数

from fractions import gcd
if N == 1:
    print(abs(x[0]-X))
elif N == 2:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    print(GCD)
else:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2, N):
        a = abs(x[i] - X)
        GCD = gcd(GCD, a)

    print(GCD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)

# 最小公倍数
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
# 引数を直接入れる
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
# 引数がリスト型
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n,x=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for i in b:
  a.append(abs(i-x))
print(gcd_list(a))

Submission status: Accepted

Solution code:
import fractions

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

for i in xl:
    l.append(abs(i - x))

ans = l[0]

for i in l:
    ans = fractions.gcd(ans, i)

print(ans)

Submission status: Accepted

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

from fractions import gcd
g = abs(A[0]-x)
for a in A:
  g = gcd(g, abs(a-x))
print(g)

Submission status: Accepted

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

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

    ans = fractions.gcd(ans, abs(x[i]-x[i-1]))

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from fractions import gcd
def main():
    readline=stdin.readline
    n,x=map(int,readline().split())
    a=list(map(int,readline().split()))

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

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy


def gcd(x, y):
    while y != 0:
        x, y = y, x % y

    return x


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

x.sort()

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

print(y)

Submission status: Accepted

Solution code:
def gcd(a,b):
    a=abs(a)
    b=abs(b)
    if a<b:
        c=a
        a=b
        b=c
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)
n,x = map(int,input().split())
xlist= list(map(int,input().split()))
ans=x-xlist[0]
for i in xlist:
    ans=gcd(ans,x-i)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import gcd


def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(n):
        a[i] =abs(a[i] - x)
 
    ans = 0
    for aa in a:
        ans = gcd(aa, ans)
    print(ans)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math

N, X = map(int, input().split())
x = list(input().split())
city = [abs(int(x[i]) - X) for i in range(N)]
MAX = min(city)
candidate = []
for i in range(int(math.sqrt(MAX)+1)):
    if MAX % (i+1) == 0:
        candidate.append(i+1)
        candidate.append(MAX // (i+1))

candidate = list(sorted(candidate, reverse=True))

for j in range(len(candidate)):
    ans = candidate[j]
    tmp = [city[i] % ans for i in range(N)]
    if max(tmp) == 0:
        print(ans)
        sys.exit()

Submission status: Accepted

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

from fractions import gcd

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

city = sorted(city)

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

for j in range(n):
    if j==0:
        ans = gcd(city[j],city[j+1])
    else:
        ans = gcd(ans,city[j])

print(abs(ans))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

sub=[]
for c in C:
  sub.append(abs(c-X))

print(gcd(sub))

Submission status: Accepted

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

n, x = map(int,input().split())
li = list(map(int,input().split()))
d = [abs(x-li[0])]
 
for i in range(n-1):
    d.append(abs(li[i]-li[i+1]))

print(gcd(*d))

Submission status: Accepted

Solution code:
from fractions import gcd

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

res = 0
for i in range(0, len(m)):
    res = gcd(res, m[i])
print(res)

Submission status: Accepted

Solution code:
from fractions import gcd

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

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xs = list(map(int, input().split()))
ds = []
for i in range(n):
  if xs[i]-x < 0:
    ds.append((xs[i]-x)*(-1))
  else:
    ds.append(xs[i]-x)
nums = sorted(list(set(ds)))
if n==1 or len(nums)==1:
  print(nums[0])
  quit()
else:
  cnd = []
  for j in range(len(nums)-1):
    a = nums[j+1]
    b = nums[j]
    while b>0:
      a,b = b, a%b
    cnd.append(a)
  print(min(cnd))

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split())
x=list(map(lambda x: abs(int(x)-X), input().split()))
x_min=min(x)
g_min=x_min
for i in x:
  g=fractions.gcd(g_min,i)
  if g==1:
    print(1)
    exit()
  if g < g_min:
    g_min = g
print(g_min)

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split())
x=list(map(lambda x: abs(int(x)-X), input().split()))
x_min=min(x)
g_min=x_min
for i in x:
  g=fractions.gcd(g_min,i)
  if g < g_min:
    g_min = g
print(g_min)

Submission status: Accepted

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

Submission status: Accepted

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

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

gcd_value = abs(X-x[0])

for i in range(1,n):
    gcd_value = gcd(gcd_value,abs(X-x[i]))

print(gcd_value)

Submission status: Accepted

Solution code:
import fractions

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

gcd_value = abs(X-x[0])

for i in range(1,n):
    gcd_value = fractions.gcd(gcd_value,abs(X-x[i]))

print(gcd_value)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

gaps = [b-a for a,b in zip(x, x[1:])]

from fractions import gcd
g1=gaps[0]
for g2 in gaps[1:]:
    g1 = gcd(g1, g2)

print(g1)