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 fractions import gcd

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

v = P[0]
for x in P[1:]:
  v = gcd(v, x)

print(v)

Submission status: Accepted

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

Submission status: Accepted

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

x = list(map(lambda x: abs(x - X), x))


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

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

Submission status: Accepted

Solution code:
# 2019/05/18
# AtCoder Beginner Contest 109 - C

# For the Answer:
# 1. Xと各点の差を出す(絶対値)
# 2. 累積最小公約数を出す

import fractions

# Input
n, x = map(int, input().split())
xl = list(map(int, input().split()))


ldif = list()
# 1. 
for i in range(n):
    ldif.append(abs(xl[i]-x))


# 2.
ac_gcd = ldif[0]
for i in range(1, n):
    ac_gcd = fractions.gcd(ac_gcd, ldif[i])

print(ac_gcd)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Skip
https://atcoder.jp/contests/abc109/tasks/abc109_c

"""
import sys

from bisect import bisect_right, bisect_left

def solve(N, X, points):
    def divisor(N):
        divisors = set()
        for i in range(1, int(N**0.5)+1):
            if N % i == 0:
                divisors.add(i)
                divisors.add(N // i)
        return sorted(divisors)

    left, right = float('inf'), float('inf')
    l = bisect_left(points, X)
    if l:
        left = points[l-1]
    r = bisect_right(points, X)
    if r != len(points):
        right = points[r]

    gaps = [abs(X-p) for p in points]
    candidates = divisor(min(abs(left-X), abs(right-X)))
    while True:
        c = candidates.pop()
        if all([g%c==0 for g in gaps]):
            return c


def main(args):
    N, X = map(int, input().split())
    points = sorted(map(int, input().split()))
    ans = solve(N, X, points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import fractions
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.append(M)
X = sorted(X)
diff = [X[i+1]-X[i] for i in range(len(X)-1)]
max_gcd = diff[0]
for i in range(1, len(diff)):
  max_gcd = fractions.gcd(diff[i], max_gcd)
print(max_gcd)

Submission status: Accepted

Solution code:
# これ問題の意味がわかりにくくない？
import fractions
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
diff = [abs(i-M) for i in X]
max_gcd = diff[0]
for i in range(1, len(diff)):
  max_gcd = fractions.gcd(diff[i], max_gcd)
print(max_gcd)

Submission status: Accepted

Solution code:
from fractions import gcd

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

l = []
for xx in x:
    l.append(abs(xx - X))

ans = l[0]
for ll in l:
    ans = gcd(ans, ll)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 15:12:31 2019

@author: avina
"""
from fractions import gcd
n,m = map(int, input().split())
l = [abs(m - int(i)) for i in input().split()]

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

Submission status: Accepted

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

li = []
for i in A:
    d = abs(i - X)
    li.append(d)

li.sort()
l = li[0]
divisors = []
for i in range(1, int(l ** (1 / 2)) + 1):
    if l % i == 0:
        divisors.append(i)
        if i != l // i:
            divisors.append(l // i)
divisors.sort(reverse = True)
for i in divisors:
    for j in li:
        count = 0
        if j % i != 0:
            count += 1
        if count != 0:
            break
    if count == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n,x=map(int, input().split())
p_list=list(map(int, input().split()))
p_list.append(x)
p_list=sorted(p_list)

df_list=[]
for j in range(len(p_list)-1):
  df_list.append(p_list[j+1]-p_list[j])

if n==1:
  print(df_list[0])
else:
  print(gcd_list(df_list))

Submission status: Accepted

Solution code:
import fractions

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

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

print(d)

Submission status: Accepted

Solution code:
from fractions import gcd

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

L = []
for l in x:
    L.append(abs(l - X))

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

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
x = list(sorted(list(map(int, input().split())) + [X]))
d = []
for a, b in zip(x, x[1:]):
  d.append(b - a)
g = 0
for v in d:
  g = gcd(g, v)
print(g)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

# 全てのx - XがDの倍数となるような最大のD
# -> x - Xの最大公約数

print(reduce(fractions.gcd, x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
N,X = [ int(it) for it in input().split() ]
li = [ abs(int(it)-X) for it in input().split() ]


gc = li[0]
for v in li[1:]:
  if ( v != 0 ):
    gc = gcd(gc,v)
print ( gc )

Submission status: Accepted

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

a = sorted(A)

def yu(a, b):
	ma = max([a, b])
	mi = min([a, b])
	while (ma % mi):
		t = ma
		mi = ma % mi
		ma = t
	return mi

ld = a[1] - a[0]
for n in range(2, N + 1):
	d = a[n] - a[n - 1]
	ld = yu(ld, d)

print(ld)

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

xlist.sort()
diclist = [xlist[i+1] - xlist[i] for i in range(N)]


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

if N > 1:
    a = gcd(diclist[0], diclist[1])
    for i in range(N-2):
        a = gcd(a, diclist[i+2])
    print(a)

else:
    print(diclist[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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


N, X = [int(i) for i in input().split()]
xs = [int(i) for i in input().split()]
diff = [abs(x - X) for x in xs]
print(gcd(*diff))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


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


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

ad = [abs(ai - x) for ai in a]

print(gcdm(ad))

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

distance_to_x0 = abs(X-x[0])
distance_to_x1 = abs(X-x[1])
candidate = fractions.gcd(distance_to_x0, distance_to_x1)

for x_i in x:
    distance = abs(X-x_i)
    candidate = fractions.gcd(candidate, distance)

print(candidate)

Submission status: Accepted

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


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


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


print(abs(g))

Submission status: Accepted

Solution code:
def gcd(x,y):
    x,y=max(abs(x),abs(y)),min(abs(x),abs(y))
    if y==0:
        return x
    if x%y==0:
        return y
    while x%y!=0:
        x,y=y,x%y
    return y

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

t=[int(j)-x for j in input().split()]
ans=abs(t.pop())
for i in t:
    ans=gcd(ans,i)

print(ans)

Submission status: Accepted

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

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

if N == 1:
    print (abs(X-lst[0]))
    sys.exit()

lst += [X]

lst2 = []
for i in range(N):
    lst2 += [abs(lst[i]-lst[i+1])]


def gcd(a,b): #aとbの最大公約数を求める
    if a < b:
        a, b = b, a
    r = a%b
    if r == 0:
        return b
    else:
        return gcd(b, r)
    return

A = lst2[0]
B = lst2[1]
C = gcd(A, B)
for i in range(2, N):
    C = gcd(C, lst2[i])

print (C)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
city = sorted(map(int, input().split()))
ans = abs(x - city[0])
if n > 1:
    dis = [city[i + 1] - city[i] for i in range(n - 1)]
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a%b)

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

for a in x:
    ans = gcd(ans, abs(a-X))
print(ans)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    while y:
        a=x%y
        x=y
        y=a
    return x

a,b=map(int,input().split())
c=list(map(int,input().split()))
c.append(b)
c.sort()
for i in range(a):
    c[-1-i]-=c[-2-i]
b=0
for i in range(a):
    b=gcd(c[i+1],b)
print(b)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x

a,b=map(int,input().split())
c=list(map(int,input().split()))
c.append(b)
c.sort()
for i in range(a):
    c[-1-i]-=c[-2-i]
b=0
for i in range(a):
    b=gcd(c[i+1],b)
print(b)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
l=list(map(lambda m:abs(int(m)-x),input().split()))
def gcd(x, y):
    if x<y:x,y=y,x
    while x % y != 0:
        x, y = y, x % y
    return y
ans=l[0]
for i in range(1,n):
    ans=gcd(ans,l[i])
print(ans)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


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


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    N, X = intin()
    xlist = intina()

    x_relative_list = [x - X for x in xlist]

    ans = None
    for xr in x_relative_list:
        xr = abs(xr)
        if ans is None:
            ans = xr
            continue
        ans = lcm(ans, xr)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def gcd(l):
    if len(l) == 1:
        return l[0]

    v = gcd2(l[0], l[1])
    for i in range(2, n):
        v = gcd2(v, l[i])

    return v


def gcd2(a, b):
    if b == 0:
        return a

    return gcd2(b, a % b)


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

x = [abs(xi - s) for xi in x]
print(gcd(x))

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())
arr=list(map(int,input().split()))
arr.append(x)
arr=sorted(arr)
arr2=[]
for i in range(n):
  arr2.append(arr[i+1]-arr[0])
if n==1:
  print(arr2[0])
else:
  ans=gcd(arr2[0],arr2[1])
  for i in range(1,n):
    ans=gcd(ans,arr2[i])
  print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,X = inpl()
xx = inpl()

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

xx.append(X)
xx.sort()
li = []
for i in range(1,N+1):
    li.append(xx[i]-xx[i-1])

ans = li[0]
for d in li:
    ans = gcd(ans,d)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd


def liner_search(n, l):
    for i in range(len(l)):
        if n < l[i]:
            return i
    return len(l)


N, X = map(int, input().split())
x = sorted(list(map(int, input().split())))
x.insert(liner_search(X, x), X)
sabun = [None] * N
for i in range(1, len(x)):
    sabun[i - 1] = x[i] - x[i - 1]
res = gcd(0, sabun[0])
for i in range(1, len(sabun)):
    res = gcd(res, sabun[i])
print(res)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
ds = [abs(int(y) - x) for y in input().split()]
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)
res = max(ds) 
for d in ds:
  res = gcd(res, d)
print(res)

Submission status: Accepted

Solution code:
from bisect import insort_left
from fractions import gcd
N,X=[int(a) for a in input().split(" ")]
xs = sorted([int(a) for a in input().split(" ")])
insort_left(xs, X)
intervals = [a-b for a, b in zip(xs[1:],xs[:-1])]
curr = intervals[0]
for i in intervals:
    curr = gcd(curr, i)
print(curr)

Submission status: Accepted

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

import numpy as np

x = np.array(list(map(int, input().split())))
x -= X

x = np.abs(x)

M = x[0]
from fractions import gcd

for i in x[1:]:
  M = gcd(M, i)

print(M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
lista = [int(i) for i in input().split()]
lista.append(x)
lista.sort()
def gcd(a,b):
    if a<b:
        a,b = b,a
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
ans = 0
for x in x_list:
    div = abs(X-x)
    ans = gcd(ans, div)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x.append(X)
x.sort()
a=x[1]-x[0]
for i in range(1,len(x)-1):
    a=fractions.gcd(a,x[i+1]-x[i])
print(a)

Submission status: Accepted

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

import numpy as np
X_abs = abs(np.array(x)-X)
#最大公約数、最小公倍数
import fractions

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

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())
L = list(map(int,input().split()))
D = [0] * N
for i in range(N):
    D[i] = abs(L[i]-X)

print(gcd(D))

Submission status: Accepted

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

distances = [0 for _ in range(N)]
for i in range(N):
    distances[i] = abs(X-City[i])

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

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

print(ans)

Submission status: Accepted

Solution code:

def Koyakusu(x, y):
    max = x if x > y else y
    min = x if x < y else y

    while max % min != 0:
        tmp = max % min
        max = min
        min = tmp
    
    return min


def maxKoyakusu(array):
    ans = array[0]
    for i in range(1, len(array)):
        ans = Koyakusu(ans, array[i])

    return ans


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

print(maxKoyakusu(a))

Submission status: Accepted

Solution code:
def GCD( a,  b ):
    if b == 0:
        # print("--" * 10)
        return a
    else:
        # print(b)
        return GCD(b, a % b)

import math
N,X = list(map(int,input().split(" ")))
xs = list(map(int,input().split(" ")))
xs = list(map(lambda x:abs(x-X),xs))
gcds = [xs[0]]
for i,x in enumerate(xs[1:]):
    gcds.append(GCD(gcds[i],x))
print(gcds[-1])

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy
import math
import itertools
from collections import Counter
from functools import reduce
from fractions import gcd


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


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

distance = [X[i]-P for i in range(N)]

ans = gcd_list(distance)
print(abs(ans))

Submission status: Accepted

Solution code:
import numpy as np
import fractions

N, X =map(int,input().split())
x = list(map(int,input().split()))
result = abs(abs(np.array(x))-X)

D= result[0]
for i in range (1,len(result)):
    D=fractions.gcd(D,result[i])
print(D)

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())
x = list(map(int, input().split()))
for i in range(N):
  x[i] = abs(x[i] - X)

print(gcd_list(x))

Submission status: Accepted

Solution code:
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a)

def solution():
    N,X = input_ints()
    Xs = input_ints()

    diffs = [abs(X-int(x)) for x in Xs]
    ans = gcd(diffs)
    print(ans)

if __name__ == '__main__':
    solution()

Submission status: Accepted

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


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

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

if N > 1:
    g = gcd(A[0], A[1])
else:
    g = A[0]

for i in A:
    g = gcd(g, i)

print(g)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

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

G = l[0]
for x in l[1:]:
    G = gcd(G, x)
print(G)

Submission status: Accepted

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

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

print(functools.reduce(gcd,diff_x))

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:
from fractions import gcd

n, start  = map(int, (input().split()))
x = list(map(int, (input().split())))
x.append(start)
sorted_x = sorted(x)

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

print(ans)

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

print(ans)

Submission status: Accepted

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


def f(st):
    xs = list(map(int, input().split()))
    sa = [abs(x - st) for x in xs]
    G = sa[0]
    for sk in sa:
        G = gcd(G, sk)
    print(G)


n, st = map(int, input().split())
f(st)

Submission status: Accepted

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

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

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


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

    
print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, X: int, x: "List[int]"):
    return reduce(gcd, [abs(X - xx) for xx in x])


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]"
    result = solve(N, X, x)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

dx = [x[i+1]-x[i] for i in range(len(x)-1)]
now = dx[0]
for i in range(1,len(dx)):
  now = gcd(now, dx[i])
print(now)

Submission status: Accepted

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

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

new_X = []
for x in X:
    new_X.append(abs(S-x))

ans = new_X[0]
for x in new_X:
    ans = min(ans,gcd(ans,x))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

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

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

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


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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

ans=0
for x_d in diff:
       ans = gcd(ans,x_d)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

tmp = 1
for i in range(len(x)-1):
    x[i+1] = f(x[i], x[i+1])

print(x[len(x)-1])

Submission status: Accepted

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

A = sorted(map(lambda x:x - X,x))

while N > 1:
    a = A[0]
    b = A[1] % a
    if b == 0:
        A.pop(1)
        N -= 1
    else:
        A[1] = a
        A[0] = b

print(abs(A[0]))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x += [X]
x.sort()
N = N+1
def GCD(x,y):
    c = x%y
    if c == 0:
        return y
    else:
        return GCD(y,c)
    
xdif = [0] * (N-1)
for i in range(1,N):
    xdif[i-1] = x[i]-x[i-1]
    if i == 1: 
        ans = xdif[i-1]
        continue
    ans = GCD(ans,xdif[i-1])
print(ans)

Submission status: Accepted

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

def algGCF(a,b):
  if a % b == 0:
    return b
  else:
    return algGCF(b,a%b)
GCF = abs(X-L[0])
for i in range(1,N):
  GCF = algGCF(GCF,abs(X-L[i]))
print(GCF)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(abs(gcd_list(x)))

Submission status: Accepted

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

ans = abs(start - x[0])
for i in range(1, n):
	dist = abs(start - x[i])
	# ans = math.gcd(ans, dist)
	# Python 3.5以上では正解になるはずだが、AtCoderでは3.4.3なのでmath.gcdが使えず、ランタイムエラーになる
	# 3.4以前ではfractions.gcdを使う必要がある。fractions.gcdは3.5以降では非推奨である
	ans = fractions.gcd(ans, dist)
print(ans)