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

    gcd_l = []
    #gcd_l.append(abs(X-x[0]))

    for i in range(0,N):
        gcd_l.append(abs(X-x[i]))
    if N==1:
        ans = gcd_l[0]
    else:
        a = [gcd_l[0],gcd_l[1]]
        ans = gcd(max(a),min(a))
        for n in range(2,len(gcd_l)):
            a = [ans,gcd_l[n]]
            ans = gcd(max(a),min(a))
    print(ans)

main()

Submission status: Accepted

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

import sys

def solve(bigN, bigX, xs):
    ys = [abs(x - bigX) for x in xs]
    g = ys[0]
    for y in ys[1:]:
        g = gcd(y, g)
    return g

def gcd(a, b):
    '''The greatest common divisor of a and b.'''
    while b > 0:
        (a, b) = (b, a % b)
    return a

def readQuestion():
    [line1, line2] = list(sys.stdin)
    [bigN, bigX] = [int(s) for s in line1.split(' ')]
    xs           = [int(s) for s in line2.split(' ')]
    return (bigN, bigX, xs)

def main():
    bigN, bigX, xs = readQuestion()
    answer = solve(bigN, bigX, xs)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys

def solve(bigN, bigX, xs):
    ys = [abs(x - bigX) for x in xs]
    g = ys[0]
    for y in ys[1:]:
        g = gcd(g, y)
    return g

def gcd(a, b):
    '''The greatest common divisor of a and b'''
    if b < a:
        (a, b) = (b, a)
    while True:
        x = a % b
        if x == 0:
            return b
        (a, b) = (b, x)

def readQuestion():
    [line1, line2] = list(sys.stdin)
    [bigN, bigX] = [int(s) for s in line1.split(' ')]
    xs           = [int(s) for s in line2.split(' ')]
    return (bigN, bigX, xs)

def main():
    bigN, bigX, xs = readQuestion()
    answer = solve(bigN, bigX, xs)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def func():
    n,x0 = map(int,input().split())
    x = [int(i) for i in input().split()]
    x.append(x0)
    x.sort()
    x.reverse()
    
    l = []
    before = 0
    before = None
    for xi in x:
        if before == None:
            before = xi
            continue
        l.append(xi-before)
        before = xi
    
    print(abs(reduce(fractions.gcd,l)))
func()

Submission status: Accepted

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

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

def gcd(a,b):
    n = max(a,b)
    m = min(a,b)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)


c.sort()
ans = c[1]-c[0]

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

print(ans)

Submission status: Accepted

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

n, x = list(map(int, input().split()))
list = list(map(int, input().split()))
list = [abs(i - x) for i in list]
min = min(list)
for num in list:
    min = gcd(min, num)
print(min)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
for i in range(N):
    x[i] = abs(x[i]-X)
y = x[0]
for i in range(N):
    if x[i]%y == 0:
        continue
    while x[i] != 0:
        y, x[i] = x[i], y % x[i]
print(y)

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 = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
D = xs[1] - xs[0]
for i in range(N):
    d = xs[i+1] - xs[i]
    D = gcd(d, D)
    if D == 1:
        print(1)
        break
else:
    print(D)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, place = [int(x) for x in input().split(' ')]
city_address = sorted([abs(int(x) - place) for x in input().split(' ')], reverse=True)
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

answer = city_address[0]
for address in city_address:
	answer = gcd(answer, address)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
x_list = [int(i) for i in input().split()]

diff_list = [max(x, x_list[i])-min(x, x_list[i]) for i in range(n)]

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    while y > 0:
        x, y = y, x%y
    return x

def multi_gcd(a):
    z = 0
    for i in a:
        z = gcd(i, z)
    return z
  
if __name__ == "__main__":
  ans = multi_gcd(diff_list)
  print(ans)

Submission status: Accepted

Solution code:
c, d = (int(i) for i in input().split())  
a = [int(i) for i in input().split()]
b = a.copy()
 
k = 0
for i in a:
    b[k] = abs(i - d)
    k += 1
 
m = min(b) 
 
def dec():
 
    i = m
    while i > 0:
        if m% i == 0: 
            k = 0
            for j in b:
                if j%i ==0:
                    k +=1
                if k==len(b):
                    return i
                
            if i == m:
                i -= i//2
                
        i -=1
 
 
 
 
                
print(dec())

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:

def euclid(a,b):
    if b == 0:
        return a 
    else:
        return euclid(b,a%b)
n,x = map(int,input().split())
cit = list(map(lambda i:int(i)-x,input().split()))

d = cit[0]
#cit-xの最大公約数
for i in range(n-1):
    d = euclid(d,cit[i+1])
    if d == 1:
        break
print(abs(d))

Submission status: Accepted

Solution code:
n,x = map(int, input().split())
l = [ abs(i - x) for i in list(map(int, input().split()))]
l.sort(reverse=True)
l = list(set(l))
if len(l) == 1:ans = l[0]
else:
  while len(l) != 1:
    l.sort(reverse=True)
    l.append(0)
    l = [ l[i] - l[i+1] for i in range(len(l) - 1)]
    l = list(set(l))
    for i in l:
      if i % min(l) != 0:break
    else:
      l[0] = min(l)
      break
  ans = l[0]
print(ans)

Submission status: Accepted

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


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

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


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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

distance = []
for i,xe in enumerate(x):
    if i is not 0:
        distance.append(xe - x[i-1])

print(reduce(fractions.gcd, distance))

Submission status: Accepted

Solution code:
def gcd(numbers):
    _min = numbers[0]
    tmp = sorted([_n % _min for _n in numbers])
    return _min if tmp[-1] == 0 else gcd(sorted([_t if _t > 0 else _min for _t in tmp]))


def solve(string):
    ins = string.split("\n")
    n, x = map(int, ins[0].split(" "))
    xs = list(map(int, ins[1].split(" ")))
    xs.append(x)
    xs = sorted(xs)
    diff = [_n - _p for _p, _n in zip(xs, xs[1:])]
    return str(gcd(diff))


if __name__ == '__main__':
    tmp = [input(), input()]
    print(solve('\n'.join(tmp)))

Submission status: Accepted

Solution code:
a=input().split()
b=input().split()
N=int(a[0])
X=int(a[1])
Xm=[abs(int(i)-X) for i in b]
def f(x,y):
    if y > x:
        x,y = y,x
    else:
        pass
    while x%y!=0:
        z = x%y
        x = y
        y = z
    return y
if len(Xm) ==1:
    print(Xm[0])
else:
    c = f(Xm[0],Xm[1])
    for i in range(len(Xm)-2):
        c=f(c,Xm[i+2])
    print(c)

Submission status: Accepted

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


def allgcd(d):
    if len(d) == 1:
        return d
    ret_gcd = d[0]
    for i in d:
        ret_gcd = gcd(ret_gcd, i)
    return ret_gcd


def maxNumVisitCity(N, X, x):
    if len(x) == 1:
        return abs(x[0] - X)

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import functools

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

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

dist = [abs(x[i] - X) for i in range(N)]
D = functools.reduce(gcd, dist)

print(D)

Submission status: Accepted

Solution code:
n,x = map(int, input().split())
city = []
sub = []
city = list(map(int, input().split()))

for i in range(len(city)):
	sub.append(abs(x - city[i]))

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


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

Submission status: Accepted

Solution code:
from functools import reduce

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

a_x = sorted([abs(a - x) for a in a_s])

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

x = reduce(gcd, a_x)
print(x)

Submission status: Accepted

Solution code:
import functools as ft
 
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
 
def gcd_list(numbers):
    return ft.reduce(gcd,numbers)
 
N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]
 
def MinusX(Xi_):
    return abs(Xi_-X)
 
def main(Xi):
    Xi = map(MinusX,Xi)
    output = gcd_list(Xi)
    print(output)
 
if __name__ == "__main__":
    main(Xi)

Submission status: Accepted

Solution code:
import functools as ft

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

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

N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]

def MinusX(Xi_):
    return abs(Xi_-X)

def main(Xi):
    Xi = map(MinusX,Xi)
    output = gcd_list(Xi)
    print(output)

if __name__ == "__main__":
    main(Xi)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

dist = [abs(X - x) for x in xi]
print(reduce(gcd, dist))

Submission status: Accepted

Solution code:
from sys import stdin


def EuclideanAlgorithm(a, b):
    if (a < b):
        a, b = b, a

    if b > 0:
        return EuclideanAlgorithm(b, a % b)
    else:
        return a


N, X = [int(a) for a in stdin.readline().rstrip().split()]
x = [int(a) for a in stdin.readline().rstrip().split()]

if len(x) == 1:
    print(abs(X - x[0]))
else:
    for i in range(len(x)):
        x[i] = abs(X - x[i])

    ans = EuclideanAlgorithm(x[0], x[1])
    for i in range(2, len(x)):
        ans = EuclideanAlgorithm(ans, x[i])

    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

def gcd(a, b):

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

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

N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]

def minusX(a):
    return abs(a-X)

Xi = map(minusX, Xi)

d = gcd_list(Xi)
print (d)

Submission status: Accepted

Solution code:
from functools import reduce
import numpy as np

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

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

N, X = tuple(map(int, input().split(" ")))
Xs = [X] + list(map(int, input().split(" ")))
Xs = map(abs, np.diff(Xs))
r = gcd_list(Xs)
print(r)

Submission status: Accepted

Solution code:
import math
from collections import defaultdict


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


def main():
    N, X = [int(a) for a in input().split()]
    Xs = [int(a) for a in input().split()]

    xs = sorted(Xs)
    a = [abs(k - X) for k in xs]

    res = a[0]
    for k in a[1:]:
        res = gcd(res, k)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

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


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

print(gcd_list(delta_x))

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd
from functools import reduce
n,x = map(int, input().split())
xs = np.asarray(list(map(int, input().split())))
diff = np.abs(xs-x)
print(reduce(gcd, diff))

Submission status: Accepted

Solution code:
n, x =  map(int, input().split())
xi = map(int, input().strip().split())
c = [x] * n
xi = [x - y for (x,y) in zip(xi,c)]
def gcd(a, b):
  if b == 0: return a
  return gcd(b, a % b)
d0 = xi[0]
for i in range(n-1):
    d = gcd(xi[i+1],d0)
    d0 = d
if len(xi) == 1:
  d = xi[0]
print(abs(d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

diff_towns = np.abs(np.diff(towns))
if len(diff_towns) == 1:
    cand = diff_towns[0]
else:
    cand = gcd(diff_towns[0], diff_towns[1])
    for i in range(2,len(diff_towns)):
        cand = gcd(cand, diff_towns[i])    

print(cand)

Submission status: Accepted

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

    return a

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

#print(cities)

if N == 1:
    print(abs(cities[0]))
else:
    ans = gcd(cities[0],cities[1])

    for i in range(1,len(cities) - 1):
        ans = gcd(ans, cities[i+1])
        #print(ans)

    print(abs(ans))

Submission status: Accepted

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

ans = x[1]-x[0]
for i in range(2, len(x)):
  v = x[i]-x[i-1]
  ans = fractions.gcd(ans, v)

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

# ユークリッドの互除法
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

# 標準入力から取得
a, b = map(int, raw_input().split())
c = map(int, raw_input().split())
# print c 
c = [abs(c[i]-b) for i in range(a)] 
# print c

g = c[0]
for z in c:
    g = gcd(g,z)
print g

Submission status: Accepted

Solution code:
import fractions

n, x = map(int, input().split())
num = list(map(int,input().split()))
d = abs(num[0]-x)
for nn in num:
	d=fractions.gcd(d, abs(nn-x))
print(d)

Submission status: Accepted

Solution code:
import fractions

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

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

t = abs(x[0] - X)
for a in x:
    t = fractions.gcd(t, abs(a - X))
print(t)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a > b:
        a, b = b, a
    while a:
        a, b = b%a, a
    return b
N,x1 = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(x1)
xs.sort()
margin = [y-x for y,x in zip(xs[1:],xs[:-1])]
m = margin[0]
for x in margin[1:]:
    m = gcd(m,x)
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
x = map(int, input().split())
r = abs(next(x) - X)
for i in x:
    r = fractions.gcd(r, abs(i - X))
print(r)

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
x = map(int, input().split())
r = abs(next(x)-X)
for i in x:
    r = fractions.gcd(r, abs(i-X))
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

d = [abs(X-x[i]) for i in range(N)]
oppai = d[0]

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


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

print(oppai)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
n, x = map(int, raw_input().split())
d = map(int, raw_input().split())
g = abs(x - d[0])
for z in d:
    g = gcd(g, abs(z - x))
print g

Submission status: Accepted

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

x = list(map(int, input().split()))
minx = min(min(x), x0)

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

gcdx = x0 - minx
for xx in x:
    gcdx = gcd(gcdx, xx-minx)

print(gcdx)

Submission status: Accepted

Solution code:
# coding: utf-8

N, X = map(int,input().split())
R = input().split()
for i in range(len(R)):
    R[i] = int(R[i])
def real(n):
    if n >= 0:
        return n 
    else:
        return -1*n 
moto = []
for i in R:
    moto.append(real(i-X))
ans = min(moto)
for i in moto:
    if i % ans != 0:
        ans = i % ans
print(ans)

Submission status: Accepted

Solution code:
import fractions
import traceback
n,x=map(int,input().split())
citys=list(map(int, input().split()))
mod_citys=citys
for i in range(len(mod_citys)):
    mod_citys[i]-=x
    if(mod_citys[i]<0):
        mod_citys[i] *= -1
if(len(mod_citys)==1):
    print(mod_citys[0])
elif(len(mod_citys)==2):
    print(fractions.gcd(mod_citys[0],mod_citys[1]))
else:
    mod_citys = sorted(mod_citys, reverse=False)
    spmin = 9999999999999
    pod = 0
    for i in range(len(mod_citys)):
        try:
            pod=fractions.gcd(mod_citys[i],mod_citys[i+1])
            if(pod<spmin):
                spmin=pod
        except:
            pass
    print(spmin)

Submission status: Accepted

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

import numpy as np
n, x = map(int, input().split())
a = np.abs(np.array(list(map(int, input().split())))-x)

if(a.shape[0] == 1):
	r = a[0]
else:
	r = gcd(a[0], a[1])
	for i in range(n-2):
		r = gcd(r, a[i+2])
print(r)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

for i in range(len(a)):
	a[i] = abs(a[i] - x)

print(reduce(fractions.gcd, a))

Submission status: Accepted

Solution code:
from functools import reduce

def lcm(a, b):
  if b > a:
    a, b = b, a
  
  while b != 0:
    a, b = b, a % b
  
  return a

city_num, start = map(int, input().split())

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

for i in range(len(cities)):
  cities[i] = abs(start - cities[i])

cities.sort()
  
a = reduce(lcm, cities)  

print(a)

Submission status: Accepted

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

city_num, start = map(int, input().split())

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

for i in range(len(cities)):
  cities[i] = abs(start - cities[i])

cities.sort()

a = cities[0]
for num in cities[1:]:
  a = lcm(a, num)
  
print(a)

Submission status: Accepted

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

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

def gcd_l(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = gcd(ret, n)
	return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd_l(*xi))

Submission status: Accepted

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

inp = input().split()
inp = [int(x) for x in inp]

p = input().split()
p = [int(x) for x in p]

ans = gcd(abs(inp[1]-p[0]), abs(inp[1]-p[0]))
for i in range(len(p)):
    ans = gcd(ans, abs(inp[1]-p[i]))

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=[]
for i in range(n):
    d.append(abs(m-a[i]))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
ans=d[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 = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l+1, 0, -1):
    if l % i == 0:
        d = True
        for item in c:
            if item % i != 0:
                d = False
        if d:
            print(i)
            break

Submission status: Accepted

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

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

y = [abs(y_i-x) for y_i in y]
m = y[0]
for y_i in y[1:]:
	m = gcd(m, y_i)
print(m)

Submission status: Accepted

Solution code:
import sys
n,x = map(int, input().split())
a = list(map(int, input().split()))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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


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


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


def aho(x):
  return x - X


B = list(map(aho, A))

C = gcd_list(B)

print(abs(C))

Submission status: Accepted

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

Submission status: Accepted

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

lis=[abs(j-X) for j in x]

print(reduce(gcd,lis))

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())
x = list(map(lambda s: abs(int(s) - X), input().split()))

if len(x) < 2:
    print(x[0])
    exit()
d = gcd(x[0], x[1])

for i in range(2, len(x)):
    d = gcd(d, x[i])
print(d)

Submission status: Accepted

Solution code:
from fractions import gcd    # math.gcd in Python 3.5
from functools import reduce

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

dist = [abs(y - X) for y in x]

print(reduce(gcd, dist))

Submission status: Accepted

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

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


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


a = [abs(i - x) for i in a]
from functools import reduce
print(reduce(gcd, a))

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x_list = [abs(int(i) - X) for i in input().split()]
# N, X = map(int, '3 81'.split())
# x_list = [abs(int(i) - X) for i in '33 105 57'.split()]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
res = [x_list[0]]
for i in range(1, N):
    res.append(gcd(res[i-1], x_list[i]))
print(min(res))

Submission status: Accepted

Solution code:
# coding: utf-8

from functools import reduce


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


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


def main():
    n, x = map(int, input().split())
    xi = map(int, input().split())

    diffs = []
    for i in xi:
        diffs.append(abs(x - i))

    print(gcd_list(diffs))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

inputs = input().split()
n = int(inputs[0])
x = int(inputs[1])
point = list(map(int, input().split()))
point.sort()
space = []

space.append(abs(x - point[0]))

for i in range(1, n):
    space.append(abs(point[i] - point[i -1]))

gcd = functools.reduce(gcd, space)

print(gcd)

Submission status: Accepted

Solution code:
import fractions

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

b=[]
for i in a:
    b.append(abs(x-i))

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

else:
    ans=fractions.gcd(b[0],b[1])

    for i in range(2,n):
        ans = fractions.gcd(ans ,b[i])

    print(ans)

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())
x = sorted([X] + list(map(int,input().split())))

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

print(ans)

Submission status: Accepted

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

def main():    
    N,X = map(int,input().split())
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    y = x[0]
    for i in range(N):
        if x[i]%y == 0:
            continue
        y = gcd(y,x[i])
    print(y)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
def main():
      global X
      global x
      print(answer(pre(X,x)))
def pre(a,b):
      b = [i-a for i in b]
      return b
def answer(k):
      Min = min([abs(i) for i in k])
      flag = False
      for i in range(1,Min+1):
            if flag == True:
                  break
            flag = True
            if Min%i==0:
                  ans = Min//i
                  for j in k:
                        if j%ans!=0:
                              flag = False
            else:
                  flag = False
      return ans
main()

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
x = [i-X for i in x]
Min = min([abs(i) for i in x])
flag = False
for i in range(1,Min+1):
    if flag == True:
        break
    flag = True
    if Min%i==0:
        ans = Min//i
        for j in x:
            if j%ans!=0:
                flag = False
    else:
        flag = False
print(ans)

Submission status: Accepted

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

n, x = map(int,input().split())
cities = list(map(int, input().split()))
min = pow(10,9)
a = []
for i in range(n):
    a.append(abs(x-cities[i]))
for i in range(n-1):
    a[i+1] = gcd(a[i],a[i+1])
print(a[-1])

Submission status: Accepted

Solution code:
import sys
import functools
import fractions

if __name__ == '__main__':
    NX = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    if len(X) == 1:
        print(abs(X[0]-NX[1]))
        sys.exit(0)

    X.append(NX[1])
    X.sort()
    diff = [X[i] - X[i-1] for i in range(1, len(X))]
    D = functools.reduce(fractions.gcd, diff)
    print(D)
    # D = min(diff)
    # while any(np.array(diff)%D):
    #     D -= 1
    # print(D)

Submission status: Accepted

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

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

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

D = gcd(diff[0],diff[1])
for i in range(2,N+1):
    D = gcd(D,diff[i])
print(D)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getGcd(num1, num2):
    while True:
        tmp = num1
        num1 = num2 % num1
        num2 = tmp
        if(num1 == 0):
            return tmp

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()

gc = xs[1] - xs[0]

for i in range(1, n + 1):
    gc = getGcd(gc,  xs[i] - xs[i - 1])

print(gc)

Submission status: Accepted

Solution code:
#encoding utf-8

import math
from functools import reduce

#複数の最大コゥ約数
def gcd(a,b):
    l = max(a,b)
    m = min(a,b)
    while m != 0:
        extra = l%m
        l = m
        m = extra
    return l

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

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

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

x.append(X)

x.sort()

minus=[]

for i in range(len(x)-1):
    minus.append(x[i+1]-x[i])


D = gcd_multi(minus)

print(int(D))