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


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


main()

Submission status: Accepted

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


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


main()

Submission status: Accepted

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


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


main()

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is None:
            ans = abs(X - x)
        else:
            div = abs(X - x)
            if div % ans:
                ans = gcd(ans, div)
    print(ans)
    return


main()

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        div = abs(X - x)
        if ans is None:
            ans = div
        elif div % ans:
            ans = gcd(ans, div)
    print(ans)
    return


main()

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        div = abs(X - x)
        if ans is None:
            ans = div
        elif abs(X - x) % ans:
            ans = gcd(ans, abs(X - x))
    print(ans)
    return


main()

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is None:
            ans = abs(X - xn[0])
        elif abs(X - x) % ans:
            ans = gcd(ans, abs(X - x))
    print(ans)
    return


main()

Submission status: Accepted

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

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

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

B.sort()

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

print(ans)

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is not None:
            if abs(X - x) % ans:
                ans = gcd(ans, abs(X - x))
        else:
            ans = abs(X - xn[0])
    print(ans)
    return


main()

Submission status: Accepted

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


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is not None:
            ans = gcd(ans, abs(X - x))
        else:
            ans = abs(X - xn[0])
    print(ans)
    return


main()

Submission status: Accepted

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


def gcd_n(numbers):
    ret = numbers[0]
    for i in range(len(numbers)):
        ret = gcd(ret, numbers[i])
    return ret


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


main()

Submission status: Accepted

Solution code:
from functools import reduce


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


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


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


main()

Submission status: Accepted

Solution code:
from functools import reduce


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


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


def main():
    N, X, *x = map(int, open(0).read().split())
    x = [abs(X - int(i)) for i in x]
    print(gcd_n(x))
    return


main()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, X0 = list(map(int, sys.stdin.buffer.readline().split()))
X = list(map(int, sys.stdin.buffer.readline().split()))
X = np.array(X, dtype=int) - X0
X = np.abs(X)

ans = reduce(gcd, X)
print(ans)

Submission status: Accepted

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

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

from fractions import gcd
from functools import reduce
g = reduce(gcd, D)
print(g)

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())
xs = list(map(int,input().split()))
xt = []
for i in xs:
    xt.append(i - x)
    
if n == 1:
    ans = xt[0]
else:
    ans = gcd(*xt)
print(abs(ans))

Submission status: Accepted

Solution code:
import functools
import fractions

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

for i in X:
    A.append(abs(i-x))

gcd = functools.reduce(fractions.gcd, A)
print(gcd)

Submission status: Accepted

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

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

A.append(X)
A.sort()

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

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

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


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

Submission status: Accepted

Solution code:

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

from fractions import gcd
from functools import reduce

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

left = diff[:] + [abs(x[0]-X)]
right = diff[:] + [abs(x[-1]-X)]

print(max(reduce(gcd, left), reduce(gcd, right)))

Submission status: Accepted

Solution code:
from functools import reduce
import fractions

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

diffs = list(map(lambda z: abs(X - z), x))
print(reduce(fractions.gcd, diffs))

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

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

print(g)

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())
lstx = [int(i) for i in input().split()]
lstx.append(x)
dx = [abs(lstx[i]-lstx[i-1]) for i in range(1,n+1)]

g = dx[0]
for i in range(1,n): 
    g = gcd(g,dx[i])

print(g)

Submission status: Accepted

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

from fractions import gcd
from functools import reduce
def koyaku(numbers):
    return reduce(gcd, numbers)

print(koyaku(sa))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n,s=map(int,input().split())
x=list(map(int,input().split()))
x2=[]
for i in x:
    x2.append(abs(i-s))

print(gcd_list(x2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd
from functools import reduce

def solve(N: int, X: int, x: "List[int]"):
    dif = []
    for i in range(N):
        dif.append(abs(x[i]-X))
    
    a = reduce(gcd,dif)
    print(a)
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X, x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
XL = list(map(int, input().split()))
XL.append(X)
XL.sort()
A = [0 for i in range(N)]
for i in range(N):
  A[i] = XL[i+1] - XL[i]
a = A[0]
for i in range(N - 1):
  b = A[i+1]
  while b != 0:
    a, b = b, a % b
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

a=abs(x-l[0])
b=1
for i in l:
    a=fractions.gcd(a,abs(i-x))
    
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

import fractions
ans = abs(x_list[0] - X)
for i in range(1, N):
    ans = fractions.gcd(ans, abs(x_list[i]-X))
print(ans)

Submission status: Accepted

Solution code:
def gcd(l, r):
  while r:
    l, r = r, l%r
  return l
N, *X = map(int, open(0).read().split())
X = sorted(X)
ans = X[1] - X[0]
for i in range(N):
  ans = gcd(ans, X[i+1] - X[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


def gcd_expand(values):
    return reduce(gcd, values)


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

x_abs = [abs(X - i) for i in x]
print(gcd_expand(x_abs))

Submission status: Accepted

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

def gcd_many(x):
	x = sorted(x)
	y = x[0]
	for i in range(1, len(x)):
		y = gcd(y, x[i])
	return y


n, x = [int(el) for el in input().split(' ')]
Y = [abs(int(el) - x) for el in input().split(' ')]
print(gcd_many(Y))

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

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

ans = abs(x[0]-X)
for _x in x:
    ans = fractions.gcd(ans, abs(_x-X))

print(ans)

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
y=list(map(int,input().split()))
lis=[]
if n==1:
  lis.append(abs(x-y[0]))
else:
  for i in range(n-1):
    lis.append(fractions.gcd(abs(x-y[i]),abs(x-y[i+1])))
print(min(lis))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    gcd = fractions.gcd
    N, X = LI()
    A = LI()
    maxD = abs(A[0] - X)
    for a in A[1:]:
        maxD = gcd(maxD, abs(X-a))
    print(maxD)
main()

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:
        a, b = x, y
    else:
        a, b = y, x

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

    return b


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:
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:
    print(abs(X[0]-x))
else:
    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:
from functools import reduce


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


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

print(reduce(gcd, 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

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
# gcdは結合法則が成り立つ
X = tuple(map(int,input().split()))
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a % b)
diff_gcd = abs(x - X[0])
for i in range(n - 1):
  diff_gcd = gcd(diff_gcd,abs(X[i + 1] - X[i]))
print(diff_gcd)

Submission status: Accepted

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

def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)

n, x = map(int, readline().split())
lst = [abs(int(i) - x) for i in readline().split()]
if n == 1:
    print(lst[0])
    quit()
p = lst[0]
for i in range(1, n):
    p = gcd(p, lst[i])
print(p)

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
distance = []
for i in range(N) :
    d = abs(x[i] - X)
    distance.append(d)
s = 1000000001
if N == 1 :
    s = distance[0]
else :
    for i in range(0,N-1) :
        s = min(fractions.gcd(distance[i],distance[i+1]),s)
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N, X = [int(x) for x in input().split()]
x = np.array([int(x) for x in input().split()])
if len(x) == 1:
    print(abs(X-x[0]))
    sys.exit()
x -= X
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
    
x.tolist()
D = gcd(* x)
print(abs(D))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def p(a,b):
    x = max(a,b)
    y = min(a,b)
    while(y!=0):
        x,y = y,x%y
    return x

N,X = map(int,input().split())
Y = [abs(X-int(i)) for i in input().split()]
ans = Y[0]
for i in range(N-1):
    ans = p(ans,Y[i+1])
print(ans)

Submission status: Accepted

Solution code:
import fractions
N,X=[int(s) for s in input().split()]
ls=[int(s)-X for s in input().split()]
a=0
for e in ls:
  a=fractions.gcd(a,e)
print(abs(a))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

Submission status: Accepted

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

Submission status: Accepted

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

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()))
tmp=[abs(i-X) for i in x]
print(reduce(gcd,tmp))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n,x = list(map(int,input().split()))
x_list = list(map(int,input().split()))
#xとx_listをまとめて考える。
x_list.append(x)
x_list.sort()
x_dif_list = [i-j for i,j in zip(x_list[1::],x_list)]

#最大公約数
import fractions

ret = min(x_dif_list)
#最大公約数を取る
for i in x_dif_list:
    ret = fractions.gcd(ret, i)
    if ret==1:
        break
print(ret)

Submission status: Accepted

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

n,x=map(int,input().split())
r=list(map(int,input().split()))
r.append(x)
r.sort()
d=[]
e=[]
for i in range(n):
  if r[i+1]!=r[i]:
    d.append(r[i+1]-r[i])
d=list(set(d))
ans=gcd(d[0],d[-1])
for y in d:
  if y%ans!=0:
    ans=gcd(ans,y)
print(ans)

Submission status: Accepted

Solution code:
from statistics import median
from fractions import gcd

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

if X < x[0]:
  ans = x[0] - X
elif X > x[len(x)-1]:
  ans = X - x[len(x)-1]
else:
  for i in range(len(x)-1):
    if x[i] < X < x[i+1]:
      if X - x[i] > x[i+1] - X:
        ans = x[i+1] - X
      else:
        ans = X - x[i] 

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


N,K=map(int,input().split())
A=[abs(int(i)-K) for i in input().split()]
print(gcd_list(A))

Submission status: Accepted

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

l = abs(X-X_list[0])
for i in range(len(X_list)-1):
  l = fractions.gcd(l,abs(X_list[i]-X_list[i+1]))
print(l)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, X = MAP()
A = MAP()

B = [abs(X-a) for a in A]

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions

n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
if len(l) == 1:
    print(abs(l[0] - x))
elif len(l) == 2:
    print(fractions.gcd(abs(l[0] - x), abs(l[1] - x)))
else:
    ans = fractions.gcd(abs(l[0] - x), abs(l[1] - x))
    for i in range(2, n):
        ans = fractions.gcd(ans, abs(l[i] - x))
    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

ans = reduce(gcd, x)

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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


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

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


main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
l=[]
for i in range(N):
    l.append(abs(X-x[i]))
def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

ll=[0]*(N+1)
for i in range(N):
    ll[i+1]=gcd(ll[i],l[i])
print(ll[N])

Submission status: Accepted

Solution code:
n,X=map(int,input().split())
x=list(map(int,input().split()))
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y,x%y) 
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:
import fractions

def lcm(a,b):
    return fractions.gcd(a,b)

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

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

ans = map_len[0]
for i in range(1, len(map_len)):
    ans = fractions.gcd(ans, map_len[i])
    i += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
n, x = [int(i) for i in sys.stdin.readline().split()]
x_ls = [int(i) for i in sys.stdin.readline().split()] + [x]
x_ls.sort()
diff_ls = [x_ls[i + 1] - x_ls[i] for i in range(n)]

def gcd(ls):
    while len(ls) > 0:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min > 0]
    return _min

res = gcd(diff_ls)
print(res)

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(1, N):
    ans = fractions.gcd(ans, abs(X - x[i]))
print(ans)

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(1, N):
    ans = fractions.gcd(ans, abs(X - x[i]))
print(ans)

Submission status: Accepted

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

N, X = map(int, input().split())
Xs = list(map(int, input().split()))
Xs.append(X)
Xs.sort()
print(reduce(gcd, np.diff(Xs)))

Submission status: Accepted

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

res_abs = []
res = []

s = 10**10

for i in range(n):
    s = abs(li[i] - x)
    res_abs.append(s)
    
    s = li[i] - x
    res.append(s)
    
res.sort()

temp = 10**10

for i in range(n-1):
    temp = min(temp, res[i+1] - res[i])

    
s = min(min(res_abs), temp)
    
while True:
    for i in range(n):
        if res_abs[i]%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x=sorted(list(map(int,input().split())))
x.append(X)
x.sort()
L=[0]*N
ans = L[0]
for i in range(N):
    L[i] = x[i+1]-x[i]
for i in range(N):
    ans = fractions.gcd(ans,L[i])
#print(x,L)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
try:
    from math import gcd
except:
    from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
l = []
for i in range(N):
    tmp = (x[i+1] - x[i])
    if tmp != 0:
        l.append(tmp)
l.sort()
ans = l[0]
for i in range(1, len(l)):
    ans = gcd(ans, l[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions as fra
import functools as fun

N, X = map(int, input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
dif = [x[i + 1] - x[i] for i in range(N)]
print(fun.reduce(fra.gcd, dif))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

n,y = map(int,input().split())
x = sorted(list(map(int, input().split())) + [y], reverse=True)
base = x.pop()
a = [i-base for i in x][::-1]
ans = reduce(gcd, a)
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[0]-X))
    exit()

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
ans = 0
a = dif[0]

for d in dif[1:]:
    ans = gcd(a, d)
    a = ans

print(ans)

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())
A =sorted(list(map(int, input().split())))
len_A=len(A)-1
A_dif=[]

for i in range(len_A):
    A_dif.append(A[i+1]-A[i])

A_X=[abs(X-i) for i in A]
A_dif=A_dif+A_X
print(gcd(*A_dif))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
A=[int(x) for x in input().split()]
if N>=2:
  Diff=[]
  for i in range(N):
    Diff +=[abs(X-A[i])]
  def gcd(a,b):#最大公約数
    return a if b == 0 else gcd(b,a%b)
  g=gcd(Diff[0],Diff[1])
  for i in range(2,N):
    g=gcd(Diff[i],g)
  print(g)
else:
  print(abs(X-A[0]))

Submission status: Accepted

Solution code:
#import math
#import fractions
from functools import reduce

'''
def gcdList(ls):
    return reduce(math.gcd, ls)
#    return reduce(fractions.gcd, ls)
'''

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

n,y = map(int,input().split())
x = sorted([int(i) for i in input().split()])
x_ = [0 for _ in range(n)]
for i in range(n):
    x_[i] = abs(y-x[i])
print(gcdList(x_))

Submission status: Accepted

Solution code:
#import math
import fractions
from functools import reduce

def gcdList(ls):
#    return reduce(math.gcd, ls)
    return reduce(fractions.gcd, ls)

n,y = map(int,input().split())
x = sorted([int(i) for i in input().split()])
x_ = [0 for _ in range(n)]
for i in range(n):
    x_[i] = abs(y-x[i])
print(gcdList(x_))

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(x)
a.sort(reverse=True)
b=[]
for i in range(n):
    b.append(a[i]-a[i+1])
import fractions as f
maxi=float('inf')
if len(b)==1:
    print(b[0])
    exit()
for i in range(n-1):
    tmp=f.gcd(b[i],b[i+1])
    maxi=min(maxi,tmp)
print(maxi)

Submission status: Accepted

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

print(reduce(gcd, x))

Submission status: Accepted

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