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

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

diff = np.diff(sorted(coord + [x])).tolist()
while len(diff) > 1:
    diff.append(gcd(diff.pop(), diff.pop()))

print(diff.pop())

Submission status: Accepted

Solution code:

def gcd(x, y):
  #assert x >= y
  return gcd(y, x%y) if y else x
 

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

dx =[abs(x-X) for x in Xn]

gcd_num = dx[0]
for x in dx:
  a, b = (gcd_num, x) if gcd_num > x else (x, gcd_num)
  gcd_num = gcd(a, b)
print(gcd_num)

Submission status: Accepted

Solution code:
#ABC109C
from functools import reduce
from fractions 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())
xx=list(map(int,input().split()))
xx.append(x)
xx.sort()
y=[]
from fractions import gcd

for i in range(n):
    y.append(xx[i+1]-xx[i])
w=y[0]
for i in y[1:]:
    w=gcd(w,i)
print(w)

Submission status: Accepted

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

def lcm(a, b):
    return a * b // gcd(a, b)

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

Submission status: Accepted

Solution code:
import numpy as np
import functools
import sys
sys.setrecursionlimit(10**9)

# 最大公約数
def gcd_impl(n,m):
    for _ in range(10):
        t = n - m
        q = m > t
        if q:
            n = m
        else:
            n = t
        if q:
            m = t
        else:
            m = m
        if m == 0:
            return n
    return gcd_impl(m, n%m)

def gcd(n,m):
    if n > m:
        return gcd_impl(n,m)
    else:
        return gcd_impl(m,n)


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

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

if n == 1:
    ans = xx[0]
else:
    ans = reduce(fractions.gcd, xx)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n,*x = map(int, open(0).read().split())
x.sort()
d = [x[i+1]-x[i] for i in range(n)]
print(reduce(gcd,d))

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

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

coord.append(X)
coord.sort()

diffs = []
for i in range(1, len(coord)):
    diffs.append(coord[i] - coord[i-1])

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

GCD = diffs[0]
for el in diffs[1:]:
    GCD = gcd(GCD, el)

print(GCD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
points = list(map(int, input().split()))
g = -1

for point in points:
  if g == -1:
    g = abs(X - point)
  g = fractions.gcd(g, abs(X - point))
print(g)

Submission status: Accepted

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

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

x -= X
x = abs(x)
x = x.tolist()

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

print(gcd(x))

Submission status: Accepted

Solution code:
#from math import gcd
from fractions import gcd
def main():
    n, x = map(int, input().split())
    L = list(set(map(int, input().split())))
    dist = sorted(set([abs(l-x) for l in L]))
    ans = dist[0]
    for d in dist:
        ans = gcd(d, ans)
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

x = [x_[i]-x0 for i in range(n)]

from fractions import gcd

g = x[0]

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

Submission status: Accepted

Solution code:


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


def submit():
    n, s = map(int, input().split())
    xlist = list(map(int, input().split()))

    if n == 1:
        print(abs(xlist[0] - s))
    else:
        dist_list = [abs(x - s) for x in xlist]
        curr = gcd(dist_list[0], dist_list[1])
        for d in dist_list[2:]:
            curr = gcd(curr, d)
        print(curr)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
n,k=map(int,input().split())
A=sorted(list(map(int,input().split()))+[k])
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
SA=[]
for  i in range(n):
    SA.append(A[i+1]-A[i])
ans=SA[0]
for i in range(n-1):
    ans=gcd(ans,SA[i+1])
print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def ggg(a,b):
	while b>0:
		nb=a%b
		na=b
		a,b=na,nb
	return a
		

def main():
	n, x = IN()
	al = list(IN())
	al.append(x)
	al.sort()
	bl=[b-a for a,b in zip(al,al[1:])]
	ret=bl[0]
	for diff in bl:
		ret = ggg(ret, diff)
	return ret
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

N,X = [int(i) for i in input().rstrip().split()]
x_list = [int(i) for i in input().rstrip().split()]
#-----

def gcd(a,b):
    x = max(a,b)
    y = min(a,b)

    while y != 0:
        r = x % y
        
        x = y
        y = r
    
    return x

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)
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())) + [x]
a.sort()
b = []
for i in range(n):
    b.append(a[i+1]-a[i])
print(gcd_list(b))

Submission status: Accepted

Solution code:
import fractions

def main():
    n, x = [int(e) for e in input().split()]
    X = [int(e) for e in input().split()]

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans



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

li = []
for i in range(n):
    li.append(abs(x[i] - y))
print(multi_gcd(li))

Submission status: Accepted

Solution code:
def main():
  import fractions
  n,X=map(int,input().split())
  x=sorted(list(map(int,input().split())))
  ans=abs(x[0]-X)
  for i in range(n):
    ans=fractions.gcd(ans,abs(x[i]-X))
  print(ans)
if __name__=='__main__':
  main()

Submission status: Accepted

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

import fractions
ans = lens[0]
for le in lens :
    ans = fractions.gcd(ans, le)

print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)
def main():
    _, X = input().split()
    x = sorted(map(int, input().split() + [X]))
    min_x = x[0]
    x = map(lambda a: a - min_x, x[1:])
    print(reduce(gcd, x))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)
def main():
    _, X = input().split()
    x = sorted(map(int, input().split() + [X]))
    min_x = x[0]
    x = map(lambda a: a - min_x, x[1:])

    def gcd(m, n):
        if n == 0:
            return m
        else:
            return gcd(n, m % n)
    print(reduce(gcd, x))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import *
from functools import *

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

print(reduce(gcd,[abs(x-x0) for x in X]))

Submission status: Accepted

Solution code:
# coding: utf-8

import fractions

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

x_list = list(map(int, input().rstrip().split(" ")))

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

print(current)

Submission status: Accepted

Solution code:
from fractions import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))
m=abs(X-x[0])

for i in range(1,N):
    #print(m,abs(x[i]-X),gcd(m,abs(x[i]-X)))
    if gcd(m,abs(x[i]-X))<m:
        m=gcd(m,abs(x[i]-X))
print(m)

Submission status: Accepted

Solution code:
import numpy as np
N, X = [int(i) for i in input().split()]
xn = np.array([int(i) for i in input().split()])
xn = abs(X-xn)

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

d = y[0]

for i in range(1, len(y)):
    d = fractions.gcd(y[i], d)

print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n, *spot = map(int, open(0).read().split())
spot.sort()
dist = set([spot[i+1]-spot[i] for i in range(n)])
print(gcd_list(dist))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x.append(X)
    x.sort()
    l = []
    for i in range(N):
        l.append(x[i+1]-x[i])
    print(reduce(fractions.gcd, l))
main()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

n, x = map(int, input().split())
city = list(map(int, input().split()))
city.append(x)
city = sorted(city)
diff = [city[i+1] - city[i] for i in range(len(city)-1)]

if len(diff)==1:
    print(diff[0])
else:
    print(gcd_list(diff))

Submission status: Accepted

Solution code:
import fractions
n,X = map(int,input().split())
x_ = list(map(int,input().split()))
x_.append(X)
x_.sort()
if len(x_) == 2:
    print(x_[1]-x_[0])
else:
    a = x_[1]-x_[0]
    for i in range(1,n):
        b = x_[i+1]-x_[i]
        a = fractions.gcd(a,b)
    print(a)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import fractions
from functools import reduce

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

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

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

P.sort()
D=[0]
for i in range(n):
    D.append(abs(P[i]-x))
print(gcd_list(D))

Submission status: Accepted

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

dist = [0] * n
for i in range(n):
    dist[i] = abs(X-x[i])
def gcd(a,b):
    if a%b == 0:return b
    return gcd(b,a%b)
if n == 1:
    print(dist[0])
    exit(0)
    
g = gcd(dist[0],dist[1])
for i in range(n):
    if i == 0:continue
    g = gcd(g,dist[i])
    
print(g)

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
ans = abs(x[0]-X)
if len(x) != 1:
    for i in range(N):
        ans1 = abs(X-x[i])
        ans = fractions.gcd(ans,ans1) 
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())
W=list(map(int,input().split()))
ans=[]
for i in W:
    ans.append(abs(i-X))

print(gcd_list(ans))

Submission status: Accepted

Solution code:
from fractions import gcd

def gcds(List):
    __ = 0
    for _ in List:
        __ = gcd(__, _)
    return __

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

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

print(gcds(y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import fractions
from functools import reduce
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
if n == 1:
    print (abs(x_list[0]-x))
    exit (0)

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

y_list = []
for i in x_list:
    y_list.append(abs(i-x))

print (gcd_list(y_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

n, X = map(int, input().split())
x = list(map(int, input().split()))
if len(x) == 1:
  print(abs(x[0] - X))
else:
  x.sort()
  s = x[1] - x[0]
  for i in range(1, n-1):
    s = gcd(s, x[i+1]-x[i])
  a = 1
  for i in range(n):
    a = max(a, gcd(abs(X-x[i]), s))
  print(a)

Submission status: Accepted

Solution code:
# 距離の最大公約数を求める

from fractions import gcd
N, X = map(int, input().split())
Xs = [int(i) for i in input().split()]

Xs.append(X)
position = sorted(Xs)

dist = []
for i in range(1, len(position)):
    dist.append(position[i] - position[i - 1])


i = dist[0]
# gcdは２数の最大公約数しか求めることができない。gcd(手前の２数の最大公約数,距離の値)とすれば全ての距離の最大公倍数が求められる。
for j in dist[1:]:
    i = gcd(i, j)

print(i)

# atcoderはpy3.4なので、上記ライブラリで動く。上記のライブラリは、py3.7では別のライブラリに統合されているので注意

Submission status: Accepted

Solution code:
from fractions import gcd
n, x = map(int, input().split())
positions = [int(i) for i in input().split()]

distances = [abs(x - p) for p in positions]
i = distances[0]
for j in distances[1:]:
    i = gcd(i, j)
print(i)

Submission status: Accepted

Solution code:
from fractions import gcd
n, x = map(int, input().split())
positions = [int(i) for i in input().split()]

distances = [abs(x - p) for p in positions]
i = distances[0]
for j in distances:
    i = gcd(i, j)
print(i)

Submission status: Accepted

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

number = []

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

import fractions 

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

x.append(X)
x.sort()

dist = []

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

ans = 0

for d in dist:
    ans = gcd(ans, d)

print(ans)

Submission status: Accepted

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

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

memo = []

for i in t:
    memo.append(abs(i-x))
ans = memo[0]
for i in range(n):
    ans = fractions.gcd(ans,memo[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))
num = x[0]-X

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

print(abs(num))

Submission status: Accepted

Solution code:
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)
y = [x[i+1]-x[i] for i in range(n)]

def eu(a, b):
    a, b = sorted([a,b])
    while a != 0:
        b, a = a, b%a
    return b
d = y[0]
for i in range(1, n):
    d = eu(d, y[i])
print(d)

Submission status: Accepted

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

Submission status: Accepted

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


n, x = map(int, input().split())
l = list(map(int, input().split()))
sa = []
for i in range(n):
    t = abs(l[i] - x)
    sa.append(t)
sa = list(set(sa))
sa.sort()

q = len(sa)
t = sa[0]

for i in range(1, q):
    t = gcd(t, sa[i])
print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

n, x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list.sort()
dis_list = []

for i in range(n):
    dis_list.append(x_list[i+1] - x_list[i])

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
P = list(map(int, input().split()))
x0 = min(min(P), X)
ans = X - x0
for x in (x - x0 for x in P):
    ans = gcd(ans, x)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
P = list(map(int, input().split()))
x0 = min(min(P), X)
P = [x - x0 for x in P]
ans = X - x0
for x in P:
    ans = gcd(ans, x)

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
P = list(map(int, input().split()))
P.append(X)
P.sort()
x0 = P[0]
P = [x - x0 for x in P]
ans = 0
for x in P:
    ans = gcd(ans, x)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().split(" ")
n = int(S[0])
x = int(S[1])

arr = [int(s) for s in input().split(" ")]

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

# import math
# def gcd(a, b):
#     return math.gcd(a, b)

def calculate(n,x,arr):
    data = []
    for ar in arr:
        if ar < x:
            data.append(x - ar)
        else:
            data.append(ar - x)

    return data

data = calculate(n,x,arr)

if len(data) == 1:
    print(data[0])
else:
    res = gcd(data[0],data[1])
    for index,da in enumerate(data):
        if index < 2:
            continue
        res = gcd(res,da)
    print(res)

Submission status: Accepted

Solution code:

def gcd(p, q):
  a, b = (p, q) if p >= q else (q, p)
  c = a % b
  while c != 0:
    a, b = (b, c) if b >= c else (c, b)
    c = a % b
  return  b

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

diffs = []

if X < xn[0]:
  diffs.append(xn[0] -X)
for n in range(N-1):
  if xn[n] < X < xn[n+1]:
    diffs.append(X - xn[n])
    diffs.append(xn[n+1] - X)
  else:
    diffs.append(xn[n+1] - xn[n])
if X > xn[N-1]:
  diffs.append(X - xn[N-1])
if len(diffs) > 1:
  D = gcd(diffs[0], diffs[1])
  for i in range(N-2):
    D = gcd(D, diffs[i+2])
else:
  D = diffs[0]
print(D)

Submission status: Accepted

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

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

print(g)

Submission status: Accepted

Solution code:
import numpy as np

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

def lcm(a,b):
    return a*b//gcd(a,b)


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

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

x.append(xx)

x.sort()

y = []

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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, X = (int(_) for _ in input().split())
    x = list(int(_) for _ in input().split())
    x.append(X)
    x.sort()
    x_diff = []
    for i in range(N):
        x_diff.append(x[i+1]-x[i])
        if i != 0:
            ans = fractions.gcd(x_diff[i],ans)
        else:
            ans = fractions.gcd(x_diff[i],x_diff[i-1])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(lambda z: abs(z-x), a))

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

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

Submission status: Accepted

Solution code:
import fractions
n,x = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]
X.append(x)
X.sort()

x_diff = [int(X[i+1] - X[i]) for i in range(n)]

ans = x_diff[0]
for y in range(1,n):
    ans = fractions.gcd(ans, x_diff[y])

print(ans)

Submission status: Accepted

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

def lcm(a, b):
  return a * b // gcd(a, b)

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

d = []
for i, j in zip(a, a[1:]):
  d.append(j - i)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n, start = map(int, input().split())
x = list(map(int, input().split()))
x.append(start)
x.sort()
# print(x)
gaps = []
for i in range(n):
    gaps.append(x[i + 1] - x[i])
# print(gaps)
if len(gaps) == 1:
    print(gaps[0])
else:
    ans = reduce(gcd, gaps)
    print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def main():
    n,x = map(int, input().split())
    X = list(map(int,input().split()))

    array = []
    for i in range(len(X)):
        array.append(abs(X[i]-x))
    gcd1 = reduce(lambda a,b: fractions.gcd(a,b), array)
    print(gcd1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def main():
    n,x = map(int, input().split())
    X = list(map(int,input().split()))

    array = []
    for i in range(len(X)):
        array.append(abs(X[i]-x))
    reduce(lambda a,b: a-b, [1,2,3])
    gcd1 = reduce(lambda a,b: fractions.gcd(a,b), array)
    print(gcd1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 
    
n,x=map(int,input().split())
xi=list(map(int,input().split()))

for i in range(n):
    if xi[i]>x:
        xi[i]=xi[i]-x
    else:
        xi[i]=x-xi[i]
    
gcdx=gcdf(xi)
print(gcdx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f = lambda:map(int,input().split())
n,x = f()
l = [x]+list(f())
m = [abs(l[i+1]-l[i]) for i in range(n)]
def gcd(a,b):
  while b:
    a,b = b,a%b
  return a
ans = m.pop()
for i in m:
  ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int,input().split())
tmp = list(map(int,input().split()))
tmp.append(x)
se = list(sorted(set(tmp)))
lis = []
for si,s in enumerate(se):
    lis.append(se[si]-se[si-1])

import fractions
a = lis
ans = a[0]
for i in range(1, len(a)):
    ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
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:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

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

tmp = []
for i in range(N):
    tmp.append(abs(x[i]-X))
mindist = min(tmp)
for i in range(N-1):
    dist.append(abs(x[i]-x[i+1]))

ans = mindist

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

print(ans)