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

xl = [abs(x-i) for i in xl]

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

n, *x = map(int, sys.stdin.read().split())

def main():
    d = abs(x[1] - x[0])
    for i in range(1, n):
        d = gcd(d, x[i+1] - x[i])
    print(d)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,X=map(int, input().split())

A=np.array(list(map(int, input().split())))
B=A-X
if N==1:
  print(abs(B[0]))
  exit()

from fractions import gcd
GCD=gcd(abs(B[0]),abs(B[1]))
#print(B)
if N>2:
  for i in range(2,N):
    GCD=gcd(GCD, abs(B[i]))
    
  
print(GCD)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

Submission status: Accepted

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

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
ans = abs(X-x[0])

for k in range(1,N):
    ans = gcd(ans,abs(x[k]-x[k-1]))
print(ans)

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

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

print(diff[0])

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

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

# targ = []
# # targ.append(abs(X - x[0]))
# for i in range(N - 1):
#     targ.append(abs(x[i + 1] - x[i]))

def mygcd(a, b):
    # print("#", a, b)
    if a < b: return mygcd(b, a)
    elif b == 0: return a
    else: return mygcd(b, a % b)

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

print(ans)

Submission status: Accepted

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

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()))
x.insert(0, X)
distance = []
for i in range(1, len(x)):
    distance.append(abs(x[i] - x[i - 1]))

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    L=[0]*N

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

    from functools import reduce
    from fractions import gcd
    print(abs(reduce(gcd,L)))


resolve()

Submission status: Accepted

Solution code:

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


def main():
    N, X = (int(i) for i in input().split())
    A = [int(i) for i in input().split()] + [X]
    A.sort()
    diff = [A[i+1] - A[i] for i in range(N)]
    ans = diff[0]
    for d in diff:
        ans = gcd(ans, d)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = []
for i in range(N):
    n.append(abs(X - x[i]))
print(reduce(gcd, n))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(ans)

Submission status: Accepted

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

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

import fractions
#import math
from functools import reduce

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

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

print(gcd_list(l))

Submission status: Accepted

Solution code:
import sys

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

def solve():
    input = sys.stdin.readline
    N, X = map(int, input().split())
    A = [int(a) for a in input().split()]
    Ans = abs(A[0] - X)
    for a in A:
        Ans = gcd(Ans, abs(a - X))
    print(Ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from itertools import accumulate


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


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

ans = list(accumulate(B, func=gcd))[-1]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd
def main():
    n, X = map(int, input().split())
    x = list(map(int, input().split()))
    x.append(X)
    x.sort()
    x = np.array(x)
    dif = np.diff(x)
    ans = 0
    for v in dif:
        ans = gcd(ans, int(v))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def solve():
    n,x = map(int,input().split())
    l = list(map(int,input().split()))
    d = abs(x-l[0])
    for i in range(1,n):
        d = gcd(d,abs(x-l[i]))
    print(d)
if __name__=='__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N,X = map(int,input().split())
W = list(map(int,input().split())) + [X]
W = sorted(W)
sa_w = [W[i+1] - W[i] for i in range(N)]
ans = reduce(gcd, sa_w)
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
W = list(map(int,input().split())) + [X]
W = sorted(W)
dist = 10**18
if len(W) == 2:
  print(W[1]-W[0])
  exit()
for i in range(1,N+1):
  dist = min(dist, W[i]-W[i-1])
  while (W[i]-W[i-1])%dist != 0:
    dist -= 1
  if dist == 1:
    break
print(dist)

Submission status: Accepted

Solution code:
from fractions import gcd
def func(a):
  return abs(int(a)-x)
n,x = map(int,input().split())
xlist = list(map(func,input().split()))
for i in range(1,n):
  xlist[i] = gcd(xlist[i],xlist[i-1])
print(xlist[n-1])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, x = map(int, readline().split())
xx = list(map(int, readline().split()))
gcd_ans = abs(x - xx[0])
for i in range(1, n):
    gcd_ans = gcd(gcd_ans, abs(x - xx[i]))
print(gcd_ans)

Submission status: Accepted

Solution code:
import fractions
from fractions import gcd


def solve():

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

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

    print(d)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import math
from functools import reduce
import fractions
#import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
n, k  = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(k)
x.sort()

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

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

ans = gcd_list(dif)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N, K = map(int, input().split())
X = sorted(list(map(int, input().split())) + [K])
# print(X)
S = [X[i+1] - X[i] for i in range(N)]
# print(S)
D = reduce(gcd, S, S[0])
print(D)

Submission status: Accepted

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

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
ans=abs(X-x[0])
for i in range(1,n):
    ans=gcd(ans,abs(X-x[i]))
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
Alist = list(map(int,input().split()))
for i in range(len(Alist)):
    Alist[i] = abs(Alist[i]-X)
Alist.sort()
p = []
q = 1
for i in range(1,len(Alist)):
    if Alist[i] % Alist[0] != 0:
        p.append(Alist[i] % Alist[0])
        q = q*0
p.sort()
r = 1
s = []
if p != []:
    for i in range(0,len(Alist)):
        s.append(Alist[i] % p[0])
        if Alist[i] % p[0] != 0:
            p[0] = Alist[i] % p[0]
if len(Alist) > 1:
    if q == 0 and r == 1:
        print(p[0])
    if q == 0 and r == 0:
        print(1)
    if q == 1:
        print(Alist[0])
else:
    print(Alist[0])

Submission status: Accepted

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

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

ans = abs(X - x[0])

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

input = sys.stdin.readline

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

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

x.append(X)
x.sort()
diff = []
ans = []

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

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

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n=int(input())
n,x=map(int,input().split())
xl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import fractions
#gcd=fractions.gcd(a,b)#最大公約数
#lcm=(a//fractions.gcd(a,b))*b #最小公倍数

res=0

for i in range(n):
    res=fractions.gcd(res,abs(x-xl[i]))

print(res)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
z=list(map(int,input().split()))
z.sort()
def gcd(a,b):
    if b==0:
        return a 
    return gcd(b,a%b)
ans=abs(x-z[0])

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n,x = map(int,input().split())
base = list(map(int,input().split()))
base_1 = [0]*n

for i in range(n):
  base_1[i] = base[i] - x
  
ans = reduce(fractions.gcd,base_1)
print(abs(ans))

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()))
res = list(map(lambda x: abs(x-X),sorted(x)))
print(reduce(gcd,res))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b==0: return a
    else: return gcd(b, a%b)
n, x = map(int, input().split())
L = list(map(int, input().split()))
d = 0
for l in L:
    d = gcd(d, abs(x-l))
print(d)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(d)

Submission status: Accepted

Solution code:
from fractions import gcd

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

x.sort()

if X < x[0]:
    d = x[0] - X
elif X > x[N - 1]:
    d = X - x[N - 1]
else:   # x[i] <= Xである最大のiを求める
    ok = 0      # x[0] <= Xを満たす
    ng = N - 1  # x[N - 1] > X
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if x[mid] <= X:
            ok = mid
        else:
            ng = mid
    d = gcd(X - x[ok], x[ok + 1] - X)

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

print(d)

Submission status: Accepted

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

import fractions
from functools import reduce
print(reduce(fractions.gcd, n))

Submission status: Accepted

Solution code:
import fractions
import sys

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

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

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(a[0]-x))
    exit()
def gcd(m,n):
    x,y=max(m,n),min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z
b=[]
for i in range(n):
    b.append(abs(a[i]-x))
c=gcd(b[0],b[1])
for i in range(n-2):
    c=gcd(c,b[i+2])
print(c)

Submission status: Accepted

Solution code:
import math
import numpy as np
import functools
import fractions
n,x=map(int,input().split())
p=list(map(int,input().split()))
p=np.array(p)
p=abs(p-x)
print(functools.reduce(fractions.gcd, p))

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
city = list(map(int, input().split()))
dist = [abs(c - x) for c in city]
#print(dist)
from fractions import gcd
from functools import reduce
ans = reduce(gcd, dist)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def Skip(n , x , xl):

    xl = map(lambda i: abs(i - x), xl)
    return reduce(gcd , xl)

def main():
    n , x = map(int , input().split())
    xl = list(map(int , input().split()))
    print(Skip(n , x , xl))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from fractions import gcd
from functools import reduce
n,x = map(int, input().split())
y_ls = list(map(int, input().split()))
y_ls.sort()
d_ls = [0] * (n-1)

if n != 1:
    first_ls = []
    for i in range(n):
        first = abs(x - y_ls[i])
        first_ls.append(first)

    for i in range(n-1):
        distance = y_ls[i+1] - y_ls[i] 
        d_ls.append(distance)

    points_gcd = reduce(gcd, d_ls)
    ans = 0
    for i in range(n):
        D = gcd(points_gcd, first_ls[i])
        if D > ans:
            ans = D

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

print(ans)

Submission status: Accepted

Solution code:
n, x = map(int,input().split())
City = list(map(int, input().split()))
Distance = [0] * n

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

Distance.sort()
ans = Distance[0]

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

for i in range(1,n):
    ans = gcd(ans, Distance[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

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

    for i in range(n):
        a[i] = abs(a[i] - x)
    
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    print(gcd_group(a))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from functools import reduce

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

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

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

N, X = i_l()
x = i_l()

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

x = gcd_list(arr + [abs(x-X) for x in x])

print(x)

Submission status: Accepted

Solution code:
n,X= list(map(int, input().split()))
x= list(map(int, input().split()))
x.append(X)
x.sort()
init=x.pop(0)
li=[]
for i in x:
    li.append(i-init)
    init=i
li.sort()
flag=0
mini=li[0]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

for i in make_divisors(mini):
    if flag==0:
        check=0
        for j in li:
            ans=i
            if j%i==0:
                check+=1
        if check==len(li):
            print(ans)
            exit(0)

Submission status: Accepted

Solution code:
import fractions as f
n,x=map(int,input().split())
A=list(map(int,input().split()))
a=[abs(x-aa) for aa in A]
for i in range(1,n): a[i]=f.gcd(a[i],a[i-1])
print(a[n-1])

Submission status: Accepted

Solution code:

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, X = map(int, readline().split())
  x = np.array(readline().split(), dtype='int64')
  x -= X
  if len(x) == 1:
    ans = x[0]
  else:
    ans = reduce(gcd, x)
  print(abs(ans))
  
  
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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

print(gcd_list(y))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import fractions

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x = [abs(i - X) for i in x]
    if len(x) == 1:
        print(x[0])
        exit()
    
    ans = fractions.gcd(x[0], x[1])
    for i in range(2,N):
        ans = fractions.gcd(ans,x[i])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


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

if N == 1:
    print(abs(X-xl[0]))
    exit(0)

xl.append(X)
xl.sort()

k = []
for i in range(1, N+1):
    tmp = xl[i]-xl[i-1]
    if not(tmp in k):
        k.append(tmp)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

def gcds(x):
    ans = x[0]
    for i in x:
        ans = gcd(ans, i)
    return ans


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

bx = X
tmp = [0 for _ in range(n)]
for i in range(n):
    tmp[i] = abs(x[i] - bx)
    bx = x[i]
print(gcds(tmp))

Submission status: Accepted

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

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

res = 0
for i in a:
    res = gcd(res, abs(i - x))
print(res)

Submission status: Accepted

Solution code:
from math import sqrt
from copy import deepcopy


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    divisors.sort(reverse=True)
    return divisors


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

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

    # まずx[0]の約数を列挙する
    div = Calc_Divisors(x[0])

    # 大きい約数から順に割っていき、割れなかったら消す
    for i in range(n):
        tmp = deepcopy(div)
        for d in tmp:
            if x[i] % d != 0:
                div.remove(d)

    print(div[0])

Submission status: Accepted

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

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

print(reduce(fractions.gcd, ans))

Submission status: Accepted

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

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

B = [abs(a - A[0]) for a in A]
ans = 0
for d in B:
    ans = gcd(ans, d)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


crt = a_abs[0]
for i in range(1, n):
    crt = gcd(crt,a_abs[i])
print(crt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,x = map(int,input().split())
X = list(map(int,input().split()))
X.append(x)
X.sort()
def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a
    
def lcm(m,n):
    return (m*n)//gcd(m,n)

pro = X[1]-X[0]

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

Submission status: Accepted

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

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

x.insert(0, X)
distance = []
for i in range(1, len(x)):
    distance.append(abs(x[i] - x[i - 1]))


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

Submission status: Accepted

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

Y = [abs(x_ - x) for x_ in X]

import fractions
#import math
from functools import reduce

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

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

print(gcd_list(Y))

Submission status: Accepted

Solution code:
N,s=map(int, input().split())
*X,=map(int, input().split())
X.sort()
X = [s] + X

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

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

Submission status: Accepted

Solution code:
from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())

print(reduce(gcd,[abs(x-i) for i in a]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
N,X = map(int,input().split())
Y = list(map(int,input().split()))
Y.append(X)
Z = [b-a for a,b in zip(Y,Y[1:])]
g = Z[0]
for z in Z:
    g = gcd(g,z)
print(abs(g))