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 a!=0 and b!=0:
        if a>b: #a<=b
            c = a
            a = b
            b = c
        b %= a
    return max(a,b)

n,x = map(int,input().split())
d = sorted(list(map(lambda a:abs(a-x),list(map(int,input().split())))))
now = d[0]
for i in d[1:]:
    now = gcd(now,i)
print(now)

Submission status: Accepted

Solution code:
#xi-xが全部Dの倍数になればいい
n,x=list(map(int, input().split()))
pos = list(map(int, input().split()))
diff_pos = [abs(s-x) for s in pos]
min_diff = min(diff_pos)
#print(min_diff)
ans = 0
def main():
    for i in range(min_diff,0,-1):
        for n in diff_pos:
            if n % i != 0:
                break
            if n == diff_pos[-1]:
                return i
    
    
print(main())

Submission status: Accepted

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

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

print(gcd(*abs_List))

Submission status: Accepted

Solution code:
from math import *
def gcd2(array):
    temp = array[0]
    for a in array[1:]:
        temp = gcd(temp, a)
    return temp
N, X = map(int, input().split())
D = []
for x in map(int, input().split()):
    D.append(abs(x-X))
print(gcd2(D))

Submission status: Accepted

Solution code:
import  math
from functools import reduce

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

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
from math import gcd
n, x = map(int, input().split())
m = [x]+list(map(int, input().split()))


m.sort()

if n==1:
  print(m[1]-m[0])
else:
  res = gcd(m[1]-m[0], m[2]-m[1])
  for i in range(1, n-1):
    a = m[i+1]-m[i]
    b = m[i+2]-m[i+1]
    if res >= gcd(a,b):
      if res%gcd(a,b)==0:
        res = gcd(a,b)
      else:
        res = gcd(res, gcd(a, b))
    else:
      if gcd(a,b)%res!=0:
        res = gcd(res, gcd(a, b))
  print(res)

Submission status: Accepted

Solution code:
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: x - X, x))
ans = min(list(map(lambda x: abs(x), x)))
for num in x:
    ans = math.gcd(ans, num)
print(ans)

Submission status: Accepted

Solution code:
import math

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

absx = [abs(X - xx) for xx in x]
absx.sort()

divx0 = []

for i in range(math.ceil(math.sqrt(absx[0])), 0, -1):
    if absx[0] % i == 0:
        divx0.append(i)

t = []
for x in divx0:
    t.append(x)
    t.append(absx[0] // x)

divx0 = t
divx0.sort(reverse=True)

for dx0 in divx0:
    isok = True
    for xx in absx:
        if xx % dx0 != 0:
            isok = False
            break

    if isok:
        print(dx0)
        exit()

Submission status: Accepted

Solution code:
import math
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = [y - X for y in x]
print(reduce(math.gcd, x))

Submission status: Accepted

Solution code:
import math
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [y - X for y in x]
if len(x)==1:
    for y in x:
        print(abs(y))
else:
    print(reduce(math.gcd, x))

Submission status: Accepted

Solution code:
import math
from functools import reduce
from sys import setrecursionlimit
setrecursionlimit(10**6)

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

n,x = map(int,input().split())
xl = list(map(int,input().split()))
xl = list(map(lambda y: abs(y-x), xl))

ans = -1
if len(xl) == 1:
    ans = xl[0]
else:
    ans = gcd(*xl)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,s = MI()
x = RI()

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

# def gcd3(*numbers):
#     return reduce(gcd, numbers)

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

ans = gcd3_list(l)
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
*C,=map(int,input().split())

t=[abs(c-X) for c in C]

import math
from functools import reduce
print(reduce(math.gcd, t))

Submission status: Accepted

Solution code:
from math import gcd
n, x0 = map(int, input().split())
x = [abs(_x-x0) for _x in list(map(int, input().split()))]
x.sort()

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

Submission status: Accepted

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
d = set()
for i in range(n):
  d.add(a[i + 1] - a[i])
d = list(d)
ans = gcd_list(d)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd

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

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

a = [abs(a-x) for a in A]

print(reduce(gcd,a))

Submission status: Accepted

Solution code:
import math

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

d =  abs(a[0] - x)

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

print(d)

Submission status: Accepted

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

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

import math
import functools
print(functools.reduce(math.gcd,xl_abs))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

a,b=map(int, input().split())
c=list(map(int, input().split()))
c = c + [b]
d = sorted(c)
l = []

for i in range(a):
    l += [d[i+1] - d[i]]

f=gcd_list(l)
print(f)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

num_list = [abs(x-xn[i]) for i in range(n)]

Ans = gcd_list(num_list)
print(Ans)

Submission status: Accepted

Solution code:
import math
import functools
N,X = map(int,input().split())
A = list(map(int,input().split()))
mylist=[abs(X-A[0])]

for i in range(len(A)-1):
    mylist.append(abs(A[i+1]-A[i]))

print(functools.reduce(math.gcd, mylist))

Submission status: Accepted

Solution code:
n,x,*l=map(int,open(0).read().split())
from math import *
a=0
for i in l: a=gcd(a,abs(i-x))
print(a)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n,x=f()
d=[abs(i-x) for i in f()]
from math import *
a=d.pop()
for i in d: a=gcd(a,i)
print(a)

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,x=f()
d=[abs(i-x) for i in f()]
a=d.pop()
from math import *
for i in d:
  a=gcd(a,i)
print(a)

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,x=f()
l=f()
d=[l[i+1]-l[i] for i in range(n-1)]
a=abs(x-l[0])
from math import *
for i in d:
  a=gcd(a,i)
print(a)

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,x=f()
l=f()
d=[x-l[0]]
for i in range(n-1):
  d+=[l[i+1]-l[i]]
a=d[0]
from math import *
for i in d:
  a=gcd(a,i)
print(a)

Submission status: Accepted

Solution code:
import math

n, x = map(int, input().split(" "))
xL = sorted(list(map(int, input().split(" "))) + [x])

diff = [0 for _ in range(n)]
for i in range(n):
    diff[i] = xL[i + 1] - xL[i]

ans = diff[0]
for d in diff:
    ans = math.gcd(ans, d)

print(ans)

Submission status: Accepted

Solution code:
from math import gcd

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

def lgcd(l):
    res = l[0]
    for i in range(1, len(l)):
        res = gcd(res, l[i])
        
    return res

x.append(X)
x.sort()
d = []
for i in range(n):
    d.append(x[i + 1] - x[i])
    
print(lgcd(d))

Submission status: Accepted

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

N,X=map(int,input().split())
x=[int(i)for i in input().split()]
dist=[abs(X-i)for i in x]
d=reduce(gcd,dist)
print(d)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd
n, x = map(int, input().split())
print(reduce(gcd, (abs(ai - x) for ai in map(int,input().split()))))

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd
n,x = map(int,input().split())
a = list(map(int,input().split()))
print(reduce(gcd,(abs(ai-x) for ai in a)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
n, x = map(int, input().split())
l = list(map(int, input().split()))


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

l_map = list(map(lambda a:abs(a-x), l))
print(gcd_list(l_map))

Submission status: Accepted

Solution code:
import math

N, X = list(map(lambda n:int(n), input().split(" ")))
x = list(map(lambda y:int(y), input().split(" ")))
x.append(X)
x.sort()
d = list(filter(lambda r: r != 0, [abs(x[i + 1] - x[i]) for i in range(len(x) - 1)]))

gcd = d[0]
for i in range(len(d)):
  gcd = math.gcd(d[i], gcd)

print(gcd)

Submission status: Accepted

Solution code:
import math
n, X = map(int, input().split())
x = list(map(int, input().split()))
X_x = [0] * n

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

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

print(gcd)

Submission status: Accepted

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, x = inintm()
X = inintl()

if x not in X:
    X.append(x)
    n += 1

X.sort()

ans = X[1] - X[0]
prev = X[0]

for i in range(1,n):
    ans = min(math.gcd(ans, X[i]-prev), ans)
    prev = X[i]

print(ans)

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

_, X = map(int, input().split())
print(reduce(gcd, (abs(i - X) for i in set(map(int, input().split())))))

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

_, X = map(int, input().split())
x = set(map(int, input().split()))
x.add(X)
x = sorted(x)
print(reduce(gcd, (j - i for i, j in zip(x[:-1], x[1:]))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, x, *X = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

print(gcd_list(l))

Submission status: Accepted

Solution code:
from math import gcd
n,x = map(int, input().split())
l = sorted([x]+list(map(int, input().split())))

nums = [0]*n
for i in range(n): nums[i] = l[i+1] - l[i]

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

Submission status: Accepted

Solution code:
from math import gcd as g
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
if x<=l[0]:
    l.insert(0,x)
elif x>=l[-1]:
    l.append(x)
else:
    for i in range(n-1):
        if l[i]<=x<l[i+1]:
            l.insert(i+1,x)
            break
ans=0
for i in range(n):
    ans=g(ans,l[i+1]-l[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

e=abs(x[0]-st)
for i in range(1,n):
    e=fractions.gcd(e,abs(x[i]-st))

print(e)

Submission status: Accepted

Solution code:
N,X=map(int,input().strip().split())
x=list(map(int,input().strip().split()))
x.append(X)
x.sort()
    
d=[]
for n in range(1,N+1):
    d.append(x[n]-x[n-1])
    
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    tmp=x%y
    if tmp==0:
        return y
    else:
        return gcd(y,tmp)
    
if len(d)<=1:
    print(d[0])
else:
    D=d[0]
    for i in range(1,len(d)):
        D=gcd(D,d[i])
    print(D)

Submission status: Accepted

Solution code:
import numpy as np

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


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

s = np.array(x)
s = abs(s-X)

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

for i in range(1, len(s)):
    if i == 1:
        D = gcd(s[i],s[i-1])
    D = gcd(s[i], D)

print(D)

Submission status: Accepted

Solution code:
from math import gcd


def main():
    n, x = map(int, input().split())
    xs = list(map(int, input().split()))
    xs.append(x)
    xs.sort()
    diff = []
    for i in range(1, n+1):
        diff.append(xs[i] - xs[i-1])
    ans = diff[0]
    for i in range(1, n):
        ans = gcd(ans, diff[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
from functools import reduce


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


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


def main():
    n, x = nm()
    X = nl()
    X.append(x)
    X = sorted(X)
    D = [X[i + 1] - X[i] for i in range(len(X) - 1)]
    ans = gcd_list(D)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc109/tasks/abc109_c
import numpy as np
import math
from functools import reduce

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

N,X = map(int,input().split())
City = np.array(list(map(int,input().split())))
City = np.sort(np.append(City,[X]))
kaisa = np.diff(City)
print(gcd_list(kaisa))

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, X = LI()
    x = LI()

    d = list(set([abs(i - X) for i in x]))
    gcd = d[0]
    for i in d:
        gcd = math.gcd(i, gcd)

    print(gcd)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import math
n,s=map(int,input().split())
X=list(map(int,input().split()))
for i in range(n):
  X[i]=abs(X[i]-s)
X.sort()
ans=10**100
for x in X:
  tmp=math.gcd(X[0],x)
  if tmp<ans:
    ans=tmp
print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

res = 0
for i in range(N):
	res = math.gcd(res, dis[i])

print(res)

Submission status: Accepted

Solution code:
import math
from functools import reduce
N,X=map(int, input().split()) 
x = list(map(int, input().split()))
y=[0]*N
for i in range(N):
    y[i]=abs(x[i]-X)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
D=y[0]
for i in range(N):
    D=gcd(y[i],D)        
print(D)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
kyori = [abs(X - x) for x in X_list]


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


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

Submission status: Accepted

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

xi = [abs(xval - x) for xval in xi]

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

res = xi[0]
for i in range(1, len(xi)):
    res = gcd(res, xi[i])

print(res)

Submission status: Accepted

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

n,x=(int(i) for i in input().strip().split(" "))
from functools import reduce
ar=[int(i) for i in input().strip().split(" ")]
ar.sort()
from bisect import insort
insort(ar,x)
temp=[]
for i in range(1,len(ar)):
    temp.append(abs(ar[i]-ar[i-1]))

k=reduce(gcd,temp)
print(k)

Submission status: Accepted

Solution code:
import math
from functools import reduce


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

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

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

# distの最大公約数が欲しい
g = gcd(*dist)
print(g)

Submission status: Accepted

Solution code:
import math

n, x = map(int, input().split())
list_x = list(map(int, input().split()))
list_x.append(x)
list_x.sort()
delta_list = []
for i in range(len(list_x) - 1):
    delta_list.append(list_x[i+1] - list_x[i])
common = delta_list[0]
for num in delta_list:
    common = math.gcd(common, num)
print(common)

Submission status: Accepted

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

x_s.append(X)

list_s=sorted(x_s)

numbers=[]

for n in range(1,N+1):
    number=list_s[n]-list_s[n-1]
    numbers.append(number)

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

number=numbers[0]
for n in range(len(numbers)):
    number=gcd(number,numbers[n])

print(number)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math

N, X = map(int, input().split())
A = sorted(list(map(int, input().split()))+[X])
B = []

for i in range(len(A)-1):
    B.append(A[i+1] - A[i])

g = B[0]

for b in B[1:]:
    g = math.gcd(b, g)

print(g)

Submission status: Accepted

Solution code:
import sys
import math
from functools import reduce
input = lambda: sys.stdin.readline().rstrip()

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

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

x.append(X)
x.sort()

diff = []

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

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

print(gcd_list(diff))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,x=map(int,input().split());l=[abs(x-i) for i in list(map(int,input().split()))];r=0
for i in range(len(l)): r=math.gcd(r,l[i])
print(r)

Submission status: Accepted

Solution code:
import math
n,x=map(int,input().split());l=[abs(x-i) for i in list(map(int,input().split()))]
if len(l)>1:
  r=math.gcd(l[0],l[1])
  for i in range(1,len(l)):
    r=math.gcd(r,l[i])
else:
  print(l[0])
  exit()
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

n, x = map(int, input().split())
a = [int(i) for i in input().split()]
b = []
for i in a:
    b.append(abs(x - i))
g = b[0]
for i in b:
    g = gcd(g, i)
print(g)

Submission status: Accepted

Solution code:
import math

n,f = map(int,input().split())
x = list(map(int,input().split()))
x.append(f)
k = min(x)
ans = max(x)-k
for i in range(n+1):
    if math.gcd(ans, x[i]-k) < ans:
        ans = math.gcd(ans, x[i]-k)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math


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

A.append(X)
A = sorted(A)

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

g = anslis.pop(0)
for c in anslis:
    g = math.gcd(g,c)

print(g)

Submission status: Accepted

Solution code:
import math

if __name__ == '__main__':
	n,x = map(int,input().split())
	A = list(map(int,input().split()))
	A.sort(reverse=True)

	B = []
	for i in range(0,n-1):
		tmp = A[i] - A[i+1]
		B.append(tmp)

	ans = abs(x-A[0])
	for j in B:
		ans = math.gcd(ans,j)
	print(ans)

Submission status: Accepted

Solution code:
import fractions
n,x = map(int,input().split())
a = list(map(int,input().split()))
res,ans = [],0
for i in range(n):
	res.append(abs(a[i]-x))
if len(res) > 3:
	D = fractions.gcd(res[0],res[1])
	for j in range(2,len(res)-2):
		D = fractions.gcd(D,res[j])
	ans = D
else:
	ans = min(res)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd

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

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

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

for i in range(1,N):
  if i == 1:
    total_gcd = gcd(diff[i],diff[i-1])
  else:
    total_gcd = gcd(diff[i],total_gcd)
    
print(total_gcd)

Submission status: Accepted

Solution code:
import math

def agcd(l):
    a=math.gcd(l[0],l[1])
    for i in range(2,len(l)):
        a=math.gcd(a,l[i])
    return a

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

print(agcd(x)if 1<N else x[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def main():
    n,x=map(int,input().split())
    p=0
    for i in map(int,input().split()):
        p = math.gcd(p, i-x)
    print(p)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
N,X = map(int,input().split())
x = list(map(int,input().split()))
y = [abs(i-X) for i in x]
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(y))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-30 18:54:32 +0900
# LastModified: 2020-07-30 19:11:26 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
def gcd(s, t):
    while t != 0:
        tmp = s % t
        s = t
        t = tmp
    return s


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    a = []
    for i, s in enumerate(x):
        if i == 0:
            a.append(abs(x[0]-X))
            continue
        a.append(abs(x[i]-x[i-1]))
    ans = a[0]
    for i in range(1, len(a)):
        ans = gcd(max(ans, a[i]), min(ans, a[i]))
        
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import math
    import functools
    n, x = map(int, input().split())
    inset = set(map(int, input().split()))
    inset2 = set()

    for num in inset:
        inset2.add(abs(num - x))

    gcd = functools.reduce(math.gcd, inset2)
    print(gcd)

            



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

print(gcd(*x))

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from math import gcd
# from numba import njit
from functools import reduce
# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,x,a):
    delta_a = (abs(a[i] - x) for i in range(n))
    return reduce(gcd,delta_a)



def main():
    # N = int(input())
    N,X = map(int,input().split())
    a = list(map(int,input().split()))
    print(solve(N,X,a))
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n,p=map(int,input().split())
a=list(map(int,input().split()))
x=[]
for i in a:
  x.append(abs(i-p))
  
if len(x)==1:
  print(x[0])
  
else:
  pin=x[0]
  for i in range(1,len(x)):
    pin=math.gcd(pin,x[i])
    
  print(pin)

Submission status: Accepted

Solution code:
import math
N,X = list(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 = math.gcd(ans, x[i])
print(ans)