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:
from functools import reduce
import bisect

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

x.sort()
bisect.insort_left(x, X)

# 都市と出発点の区間の長さの最大公約数が解
diff = [abs(x[idx] - x[idx-1]) for idx in range(1,N+1)]
print(reduce(gcd,diff))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n, x = list(map(int, input().rstrip('\n').split()))
    xl = list(map(int, input().rstrip('\n').split()))
    xl.append(x)
    xl.sort()
    gcd = 0
    for i in range(1, len(xl)):
        gcd = fractions.gcd(gcd, xl[i] - xl[i-1])
    print(gcd)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

X=X+[x]
X.sort()
sa=[0]*n
for i in range(1,n+1):
  sa[i-1]=X[i]-X[i-1]
if len(sa)==1:
  print(sa[0])
else:
  ans=sa[0]
  for i in range(1,n):
    ans=gcd(ans,sa[i])
  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()))

print(reduce(gcd, [abs(x[i] - X) for i in range(N)]))

Submission status: Accepted

Solution code:
import fractions
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i in b[1:]:
        ans=fractions.gcd(ans,i)
    print(ans)

Submission status: Accepted

Solution code:
import math
import fractions
n,x = map(int,input().split())
l  = sorted(map(int,input().split()+[x]))
dec = []
for i in range(n):
    j = abs(l[i-1]-l[i])
    dec.append(j)
ans = dec.pop()
for i in dec:
    ans = fractions.gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
l = sorted(map(int, input().split()+[X]))
r = [l[n+1] - l[n] for n in range(N)]
ans = r.pop()
for i in r:
    while ans%i != 0:
        ans,i = i,ans%i
    ans = i
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N,X = map(int, input().split())
    r = [abs(X-i) for i in map(int, input().split())]
    ans = r.pop()
    for i in r:
        while ans%i != 0:
            ans,i = i,ans%i
        ans = i
    return ans

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
r = {abs(X-i) for i in map(int, input().split())}
ans = r.pop()
for i in r:
    while ans%i != 0:
        ans,i = i,ans%i
    ans = i
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
r = [abs(X-i) for i in map(int, input().split())]
ans = r.pop()
for i in r:
    while ans%i != 0:
        ans,i = i,ans%i
    ans = i
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
l = sorted(map(int, input().split()+[X]))
r = [l[n+1] - l[n] for n in range(N)]
ans = r.pop()
for i in r:
    while ans%i != 0:
        ans,i = i,ans%i
    ans = i
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(g)

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

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

data = getInputListInt()

data.append(x)

data.sort()

tmp = []

for i in reversed(range(1, n+1)):
    tmp.append(data[i]-data[i-1])



gcdans = reduce(fractions.gcd, tmp)

print(gcdans)

Submission status: Accepted

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


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


x_n.sort()
min_start = abs(x_n[0] - x)
for i in range(1, len(x_n)):
    tmp = abs(x_n[i] - x)
    if min_start > tmp:
        min_start = tmp

ans = min_start
for i in range(1, len(x_n)):
    ans = gcd(ans, abs(x_n[i] - x_n[i-1]))
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
cities = list(map(int,input().split()))
dist = []
for city in cities:
    dist.append(abs(city-x))

gcf = dist[0]

def gcd(x,y):
    a = max(x,y)
    b = min(x,y)
    while a%b !=0:
        a,b = b,a%b
    return b
for i in dist:
    gcf = gcd(gcf,i)
print(gcf)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))

Submission status: Accepted

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

# x間の最小公倍数が答え
from functools import reduce
import fractions

x=sorted(x)
x_bet=[0]*(n-1)

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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


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


ns = [abs(x-X) for x in XS]
print(gcd_list(ns))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

xsas = [abs(xi-x) for xi in xis]

if n == 1:
    print(xsas[0])
else:
    res = fractions.gcd(xsas[0],xsas[1])
    for xsa in xsas:
        res = fractions.gcd(res,xsa)
    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C問題
#gcd(二つの数)
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
N,X = map(int,input().split())
C = list(map(int,input().split()))

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

for i in range(N):
    if i == 0:
        g = D[0]
    else:
        g = gcd(g,D[i])
        
print(g)

Submission status: Accepted

Solution code:
import fractions
a,b = [int(i) for i in input().split()]

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

l2 = [abs(i-b) for i in l]

ans = l2[0]

for i in range(len(l2)):
    ans = fractions.gcd(l2[i],ans)
    
print(ans)

Submission status: Accepted

Solution code:
import fractions

n,start=map(int,input().split())
x=list(map(int,input().split()))
dist=[]
for i in range(n):
    dist.append(abs(x[i]-start))
ans=dist[0]
for i in range(1,n):
    ans=fractions.gcd(ans,dist[i])

print(ans)

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
mx=min(x)
x=list(map(lambda t:t-mx,x))
def gcd(a,b):
    while b:
        a,b=b,a%b
    return(a)
a=10**10
for i,j in zip(x,x[1:]):
    a=min(a,gcd(i,j))
print(a)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

dists = [abs(x - X) for x in xs]
D = gcd(dists[0], dists[1])
for d in dists[2:]:
    D = gcd(D, d)

print(D)

Submission status: Accepted

Solution code:
import fractions
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
d = []
for i in range(n):
    d.append(x[i+1]-x[i])
ans = d[0]
for j in range(1, len(d)):
    ans = fractions.gcd(ans, d[j])
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()))
D=abs(x[0]-X)
for i in range(N):
  D=gcd(D,abs(X-x[i]))
print(D)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  s=make_divisors(x[0]-m)
  news=[]
  for i in range(1,n):
    d=x[i]-x[i-1]
    news=[]
    for j in s:
      if d%j==0:
        news.append(j)
    s=set(news)
  print(max(s))
  
main()

Submission status: Accepted

Solution code:
import os, sys, re, math

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

N,X = map(int,input().split(' '))
cities = list(map(lambda x: abs(int(x) - X),input().split(' ')))
D = cities[0]

for i in range(len(cities)):
    D = gcd(D, cities[i])

print(D)

Submission status: Accepted

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

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, x = nm()
xl = nl()

xl.append(x)

heapq.heapify(xl)


hl = []

last = heapq.heappop(xl)
for i in range(n):
    h = heapq.heappop(xl)
    hl.append(h-last)

print(reduce(gcd,hl))

Submission status: Accepted

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

n, start = [int(a) for a in input().split()]
x = [int(b) for b in input().split()]
x = x + [start]
mi = min(x)

g = abs((x[1] - mi) - (x[0] - mi))
for i, v in enumerate(x):
    if (i > 0):
        d = abs((x[i] - mi) - (x[i - 1] - mi))
        g = gcd(g, d)
        
print (g)

Submission status: Accepted

Solution code:
line = raw_input()
N, X = [int(s) for s in line.split(' ')]
line = raw_input()
xs = [int(s) for s in line.split(' ')]
xs.append(X)
#xs = [x - X for x in xs]
xs.sort()
X = 0
if len(xs) == 1:
    print abs(xs[0])
else:
    sub = [abs(a - b) for a, b in zip(xs[1:], xs)]
    sub.sort()
    ret = sub[0]
    for s in sub[1:]:
        mod = 1
        ss = ret
        while mod > 0:
            mod = s % ss
            s = ss
            ss = mod
        ret = s
    print ret

Submission status: Accepted

Solution code:
import os, sys, re, math

from fractions import gcd

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

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

g = d[0] if len(d) == 1 else gcd(d[0], d[1])
for i in range(len(d) - 2):
    g = gcd(g, d[i + 2])

print (g)

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split(' ')))
xs = [abs(X - c) for c in list(map(int, input().split(' ')))]
def gcd(l, s):
    return s if l % s == 0 else gcd(s, l % s)
    
g = xs[0]
for i in xs:  # 1e5
    g = gcd(i, g)

print(g)

Submission status: Accepted

Solution code:
import fractions

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


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

print(gcd)

Submission status: Accepted

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

if __name__ == '__main__':
    N, Xini = map(int, input().split())
    X = list(map(int, input().split()))
    for i in range(N):
        X[i] = abs(X[i] - Xini)
    
    before = X[0]
    for i in range(1, N):
        before = gcd(X[i], before)
    
    print(before)

Submission status: Accepted

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

N, X = map(int, input().split())
x = sorted(list(map(lambda x:int(x) - X, input().split())))
y = []

if N == 1:
  print (abs(x[0]))
  sys.exit()
elif N == 2:
  print (gcd(abs(x[0]), abs(x[1])))
  sys.exit()
for i in range(N-1):
  y.append(x[i+1]-x[i])

ans = y.pop()
while y:
  ans = gcd(ans, y.pop())
print (ans)

Submission status: Accepted

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

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

x = x + [X]
x.sort()
ans = x[1] - x[0]

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

Submission status: Accepted

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

l=[abs(x[i]-X) for i in range(N)]
temp=fractions.gcd(l[0], l[1])
if N==2:
  print(temp)
  exit()
  
for i in range(2, N):
  temp=fractions.gcd(temp, l[i])
  
print(temp)

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

    else:
        return gcd(b, a % b)

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

else:
    output = gcd(abs(x - X[0]), abs(X[0] - X[1]))

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

print(output)

Submission status: Accepted

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


def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    B = [abs(A[i]-X) for i in range(N)]
    print(reduce(gcd, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

N, X = [int(elem) for elem in input().split()]
xs = [int(elem) for elem in input().split()]

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

diff = []
for x1, x2 in zip(xs[:-1], xs[1:]):
  diff.append(x2 - x1)

if len(diff) > 1:
  res = fractions.gcd(diff[0], diff[1])
  for elem in diff[2:]:
    res = fractions.gcd(res, elem)
  print(res)
else:
  print(diff[0])

Submission status: Accepted

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

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

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

print(gcdlist(b))

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b<a:
        a,b = b,a
    while b>0:
        a,b = b,a%b
    return a
N,X = map(int,input().split())
A = list(map(int,input().split()))
if N==1:
    D = abs(X-A[0])
else:
    D = gcd(abs(X-A[0]),abs(X-A[1]))
    for i in range(2,N):
        D = gcd(D,abs(X-A[i]))
print(D)

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
    else:
        return(gcd(b, a % b))

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
import numpy as np
N, X = map(int, input().split())
xlist = list(map(int, input().split()))
xlist.append(X)
xlist.sort()
sa = list(np.array(xlist[1:]) - np.array(xlist[:-1]))
print(reduce(fractions.gcd, sa))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
for i in lst:
    ans.append(abs(i-X))
small = min(ans)
for i in ans:
    if i%small != 0:
        while i%small != 0:
            i = i%small
            small = small - i
print(small)

Submission status: Accepted

Solution code:
import numpy as np
import fractions

def q74(N, X, x):
    y = np.array(x)
    z = abs(y - X)
    
    ans = z[0]
    for i in range(1, N):
        ans = fractions.gcd(ans, z[i])
    return ans


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


print(q74(N, X, x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,xstart=map(int,input().split())
x=map(int,input().split())
z=[];za=z.append
for i in x:
  za(abs(xstart-i))
import fractions;g=fractions.gcd
a=z[0]
for i in range(n-1):
  a=g(a,z[i+1])
print(a)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
from fractions import gcd


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

places = np.array(list(map(int, input().split())))

distances = abs(places - X)

answer = reduce(gcd, distances)
print(answer)

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

sub = []
for p in point:
    sub.append(abs(p-x))

print(gcd_list(sub))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from fractions import gcd

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

A = [0] * N
for i in range(N):
    A[i] = abs(M-X[i])

#print(A)

gc = A[0]
for i in range(N):
    gc = gcd(gc, A[i])

print(gc)

Submission status: Accepted

Solution code:
from bisect import bisect
from fractions import gcd


def solve(N, SP):
    _x = list(map(int, input().split()))
    diff = []
    _x.sort()
    sp_pos = bisect(_x, SP)

    x = _x[0:sp_pos] + [SP] + _x[sp_pos:]

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

    if len(diff) == 1:
        ans = diff[0]
    else:
        ans = diff[1]-diff[0]
        for d in diff[1:]:
            if ans == 1:
                break
            else:
                ans = gcd(ans, d)
    return ans


if __name__ == '__main__':
    n, sp = map(int, input().split())
    print(solve(n, sp))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n,x=map(int,input().split())
    A=list(map(lambda y:int(y)-x,input().split()))
    if n==1:
        print(abs(A[0]))
        return
    from fractions import gcd
    from functools import reduce
    print(abs(reduce(gcd,A)))
resolve()

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

#x_list.append(X)
x_list_new=sorted(x_list)
x_list_new_dif=[abs(x_list_new[i]-X) for i in range(len(x_list_new))]

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

Submission status: Accepted

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

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

g = abs(x[0]-s)

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

print(g)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



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



n, x = LI()
L = [abs(i-x) for i in LI()]
print(reduce(lambda p, q:gcd(p, q), L))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from bisect import insort_left
from fractions import gcd
def lcm(m,n):
    return (m*n)//gcd(m,n)
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
g=x[1]-x[0]
for i in range(n):
    g=gcd(g,x[i+1]-x[i])
print(g)

Submission status: Accepted

Solution code:
# ABC109C - Skip
from fractions import gcd


def main():
    N, X, *A = map(int, open(0).read().split())
    ans = abs(X - A[0])
    for i in A:
        dif = abs(X - i)
        if dif % ans:
            ans = gcd(ans, dif)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    N, X, *A = map(int, open(0).read().split())
    ans = abs(X - A[0])
    for i in A:
        dif = abs(X - i)
        if dif % ans:
            ans = gcd(ans, dif)
    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()))
res = 0
for i in range(N):
  res = gcd(abs(X - x[i]), res)
print(res)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

sys_input = sys.stdin.readline

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

dp = [None] * N
dp[0] = xxx[0]

for i, x in enumerate(xxx):
    if i == 0:
        continue
    dp[i] = gcd(dp[i-1], x)

print(dp[N-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
#print(y)

max_gcd=y[0]
for i in range(N):
  max_gcd=fractions.gcd(max_gcd,y[i])
print(max_gcd)

Submission status: Accepted

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


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


y = [abs(X - x[0])]
for i in range(len(x) - 1):
    y.append(abs(x[i + 1] - x[i]))

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

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

Submission status: Accepted

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

import fractions

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

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

Submission status: Accepted

Solution code:
import numpy as np
import math
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_init = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()

x_list_np = np.asarray(x_list)

idx = np.abs(x_list_np - x_init).argmin()

if x_list[idx]==x_init:
    pass
elif x_list[idx]<x_init:
    x_list_np = np.insert(x_list_np, idx+1, x_init)
else:
    x_list_np = np.insert(x_list_np, idx, x_init)

x_list_np_diff = x_list_np[:-1] - x_list_np[1:]

print(np.abs(gcd(*x_list_np_diff)))

Submission status: Accepted

Solution code:
def gcd1(x,y):
    d = x % y
    while d != 0:
        x,y = y,d
        d = x % y
    return y

def gcd(x,y):
    if x < y:
        x,y = y,x
    return gcd1(x,y)

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

xList.append(X)
xList.sort()
dList = []
for i in range(len(xList)-1):
    d = xList[i+1]-xList[i]
    dList.append( d )

if len(dList) == 1:
    print( dList[0])
else:
    d = gcd(dList[0],dList[1])
    for i in range(2,len(dList)):
        d = gcd(d,dList[i])
    print(d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
li = list(map(int, input().split()))
t = []
for i in li:
    t.append(abs(i - x))
divisors = []
for i in range(1, int(min(t) ** 0.5) + 1):
    if min(t) % i == 0:
        divisors.append(i)
        if i != min(t) // i:
            divisors.append(min(t) // i)
divisors.sort()
divisors = divisors[::-1]
for j in divisors:
    if all(k % j == 0 for k in t):
        print(j)
        exit()

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xs = list(map(int, input().split()))
ds = [abs(y - x) for y in xs]


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


ds = sorted(ds, reverse=True)
res = ds[0]
for d in ds[1:]:
    if d == 0:
        continue
    res = gcd(res, d)
print(res)

Submission status: Accepted

Solution code:
import fractions
import numpy as np
n,x=map(int,input().split())
li=np.array(input().split(),dtype=np.int64)

li=abs(li-x)

if n==1:
    print(li[0])
else:
    ans=0
    for i in li:
        ans=fractions.gcd(ans,i)
    print(ans)

Submission status: Accepted

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

dis_list = [abs(int(i) - X) for i in input().split()]
if len(dis_list) < 2:
    print(dis_list[0])
    sys.exit()


first_gc = math.gcd(dis_list[0], dis_list[1])

for i in range(len(dis_list)):
    first_gc = math.gcd(first_gc, dis_list[i])

print(first_gc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

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

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

print(res)

Submission status: Accepted

Solution code:
from fractions import gcd

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

tmp = [0] * N
x.sort()
tmp[0] = abs(X - x[0])

for i in range(N - 1):
    tmp[i + 1] = x[i + 1] - x[i]

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

print(ans)

Submission status: Accepted

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