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


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


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

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a = np.array(list(set(a)))
a.sort()
diff = a[1:] - a[:-1]

# print(a - x)
diff = list(diff)
tmp = diff[0]
for i in diff[1:]:
    tmp = gcd(tmp, i)
print(tmp)

# print(diff.min())

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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


def kouyakusuu(kyori, num):
    ans = kyori[0]
    pre = kyori[0]
    for i in range(num - 1):
        now_point = kyori[i + 1]
        while now_point:
            pre, now_point = now_point, pre % now_point
        if pre < ans:
            ans = pre
        pre = kyori[i + 1]
    return ans


def main():
    num, start = map(int, input().split())
    data = list(map(int, input().split()))
    kyori = [0 for i in range(num)]

    for i in range(num):
        kyori[i] = abs(data[i] - start)

    ans = kouyakusuu(kyori, num)

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

x_processed = list(set([abs(x - X) for x in x_list]))

x_processed.sort()

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

x1 = x_processed[0]
for x2 in x_processed[1:]:
    x1 = func(x2, x1)
    
print(x1)

Submission status: Accepted

Solution code:
import fractions

N, X = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(X)
cities.sort()
distances = list(map(lambda x: cities[x + 1] - cities[x], range(len(cities) - 1)))
ans = distances[0]
for distance in distances:
    ans = fractions.gcd(ans, distance)
print(ans)

Submission status: Accepted

Solution code:
from numpy import*
from functools import*
from fractions import*
n,X,*x=map(int,open(0).read().split())
print(reduce(gcd,list(abs(array(x)-X))))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

x.append(X)
sorted_x = sorted(x)
min_sorted_x = sorted_x[0]
dists = ([n - min_sorted_x for n in sorted_x])[1:]
print(reduce(gcd,dists))

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

print(ans)

Submission status: Accepted

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

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

new_x = []
for i in x:
    new_x.append(abs(i - X))

if len(x) == 1:
    print(new_x[0])
    exit()
else:
    for i, j in enumerate(new_x):
        if i == 0:
            res = gcd(new_x[0], new_x[1])
        else:
            res = gcd(res, new_x[i])

print(res)

Submission status: Accepted

Solution code:
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy

from bisect import bisect_left as bl

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

y=[]
for i in range(N):
    y.append(abs(x[i]-X))
ans=y[0]
for i in y:
    ans=gcd(ans,i)
print(ans)

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))
while len(b)>1:b.append(fractions.gcd(b.pop(-1),b.pop(-1)))
print(b[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())

ans = 0


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

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = gcd(ans, a[i])


print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import fractions
n, x = list(map(int, input().split()))
x_li = list(map(int, input().split()))
x_li.append(x)
x_li.sort()
d = []
for i in range(n):
    d.append(x_li[i + 1] - x_li[i])


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


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


if len(d) > 1:
    print(gcd_list(d))
else:
    print(d[0])

Submission status: Accepted

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

if N==1:
    print(s[0])
else:
    r = gcd(s[0], s[1])
    if N==2:print(r)
    else:
        for i in range(2, N):
            r = gcd(r,s[i])
        print(r)

Submission status: Accepted

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

def f(m,n):
  if min(m,n)<0:
    return f(abs(m),abs(n))
  elif m<n:
    return f(n,m)
  elif m%n==0:
    return n
  else:
    return f(n,m%n)
ans=abs(X[0]-x)
for i in range(1,n):
  ans=f(ans,X[i]-x)
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()
diff = []
for i in range(N):
  diff.append(x[i+1]-x[i])

ans = diff[0]
for i in range(N):
  ans = gcd(ans, diff[i])
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)


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


if __name__ == '__main__':
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))
    x_list.append(x)
    x_min = min(x_list)
    for i in range(len(x_list)):
        x_list[i] -= x_min
    print(list_gcd(x_list))

Submission status: Accepted

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

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

def solve(N: int, X: int, x: "List[int]"):
    dis = []
    for a in x:
        dis.append(abs(X - a))
    ret = dis[0]
    for i in range(1, len(dis)):
        ret = gcd(ret, dis[i])
    print(ret)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
m=list(map(lambda y:int(y)-x,input().split()))
if 0 in m:
  m.remove(0)
ans=abs(m[0])
for i in m:
  i=abs(i)
  while 1:
    ans%=i
    ans,i=i,ans
    if i==0:
      break
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
n,x=map(int,input().split())
y=list(map(int,input().split()))
def gcd(num):
    return reduce(fractions.gcd, num)
ya=[abs(y[i]-x) for i in range(n)]
print(gcd(ya))

Submission status: Accepted

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

x.append(a)
x.sort()

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

import fractions
from functools import reduce

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

print(gcd_list(diff_all))

Submission status: Accepted

Solution code:
#coding: utf-8
from functools import reduce
from fractions import gcd    #py<=3.4
#from math import gcd    # py >= 3.5
N, X = map(int, input().split())
x = list(map(int, input().split()))
res = [abs(x[i] - X) for i in range(N)]
print(reduce(gcd, res))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	
	max1 = 2000000001
	if tmp < len(L):
		max1 = L[tmp]
	
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	seed = 0
	mark = -1
	if abs(max1-X) < abs(X-min1):
		seed = abs(max1-X)
		mark = tmp
	else:
		seed = abs(X-min1)
		mark = tmp-1
	
	ans = 2000000001
	for i, val in enumerate(L):
		if i == mark:
			continue
		tmp = abs(L[i] - L[mark])
		ans_tmp = gcd(tmp, seed)
		if ans > ans_tmp:
			ans = ans_tmp
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

xdef = [abs(x[i]-X) for i in range(N)]
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

if N == 1:
  print(xdef[0])
else:
  tmp = gcd(xdef[0], xdef[1])
  for i in range(1,N):
    tmp = gcd(tmp,xdef[i])
  print(tmp)

Submission status: Accepted

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

points= [ abs(int(s)-initialPoint) for s in input().split(" ") ]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

if n == 1:
    print(points[0])
    exit()

now=gcd(points[0], points[1])
for i in range(2, len(points)):
    now = gcd(now, points[i])

print(now)

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

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

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

    
x.sort()
sa = [0]*(N)
for i in range(N):
    sa[i] = x[i+1] - x[i]
    
for i in range(1, N):
    sa[i] = gcd(sa[i-1], sa[i])

print(sa[-1])

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
dif = []
for i in range(N):
    dif.append(xs[i+1] -xs[i])
if len(dif) > 1:
    ans = fractions.gcd(dif[0], dif[1])
    for i in range(N):
        ans = fractions.gcd(ans, dif[i])
    print(ans)
else:
    print(dif[0])

Submission status: Accepted

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
if len(x) < 2:
    print(x[0])
else:
    D = gcd(x[0], x[1])
    for i in range(2, N):
        D = gcd(D, x[i])

    print(D)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
from sys import stdin
N, X = [int(_) for _ in stdin.readline().rstrip().split()]
xs = [int(_) for _ in stdin.readline().rstrip().split()]
xs.sort()
diff = [xs[i] - xs[i-1] if i > 0 else abs(xs[i]-X) for i in range(N)]
gcd = reduce(fractions.gcd, diff)
print(gcd)

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

g = x[0]
for xx in x[1:]:
    g = gcd(g, xx)
print(g)

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

g = x[0]
for xx in x:
    g = gcd(g, xx)
print(g)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = x + [X]
x.sort()
# 最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
diff = [x[i+1] - x[i] for i in range(N)]
if len(diff) == 1:
    print(diff[0])
    exit()
ans = gcd(diff[0], diff[1])
for i in range(2, N):
    ans = gcd(ans, diff[i])
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import fractions


def solve(N: int, X: int, x: "List[int]"):
    x.sort()
    gMax = None
    last = None
    begin = 0
    if abs(X - x[0]) > 0:
        last = abs(X-x[0])
        gMax = last
    else:
        begin = 1
        last = x[1]-x[0]
        gMax = last
    for i in range(begin, N-1):
        next = x[i+1] - x[i]
        gMax = fractions.gcd(gMax, next)
    print(gMax)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X, x)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = max(Y)
for y in Y:
    ans = gcd(y,ans)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

Submission status: Accepted

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

inpl = lambda: list(map(int,input().split()))
N, X = inpl()
x = inpl()
y = [ p - X for p in x ]
print(abs(gcd_list(y)))

Submission status: Accepted

Solution code:
def main():
	N, X = map(int, input().split())
	x = list(map(int, input().split()))
	x.append(X)
	x.sort()
	diff = [0]*N
	for i in range(N):
		diff[i] = x[i+1] - x[i]

	def gcd(a, b):
		if (b == 0):
			return a
		else:
			return gcd(b, a%b)
	ans = diff[0]
	for c in diff[1:]:
		ans = gcd(ans, c)

	print(ans)


if __name__ == '__main__':
    main()

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

dist = [abs(X - x[i]) for i in range(N)]
print(gcd(dist))

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xlist = [int(n) for n in input().split()]
dis_list = [abs(x - y) for y in xlist]
dis_list = sorted(dis_list)

def gojo(num1, num2):

	if num2 == 0:
		return num1
	else:
		return gojo(num2, num1 % num2)
if n == 1:
	print(dis_list[0])
else:
	gcd = gojo(dis_list[1], dis_list[0])
	for i in range(1, n):
		gcd = gojo(dis_list[i], gcd)
	print(gcd)

Submission status: Accepted

Solution code:
import fractions
import sys

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

gcd = d_min
for i in dif:
    tmp = fractions.gcd(gcd, i)
    if tmp == 1:
        print(1)
        sys.exit()
    else:
        gcd = tmp

print(gcd)

Submission status: Accepted

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

Submission status: Accepted

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

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

x.append(X)
x.sort()

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

now = x[1] - x[0]

for i in range(1, N):
    distance = x[i+1] - x[i]
    now = gcd(now, distance)
    if now == 1:
        break
print(now)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

xi.append(X)
xi.sort()

diffs = []
for i in range(N):
    diffs.append(xi[i+1] - xi[i])

ans = reduce(fractions.gcd, diffs)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
#from math import factorial
from math import sqrt

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

Submission status: Accepted

Solution code:
import math

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


N,X = map(int,input().split())
x = input().split()
xls = []
 
for n in range(0,N):
    xls.append(int(x[n]))
 
xls.append(X)
xls.sort(reverse = True)
 
tousa = []
 
for n in range(0,N):
    tousa.append(xls[n]-xls[n+1])
 
if len(tousa) == 1:
    print(tousa[0])
    exit()
gcdd = gcd(tousa[0],tousa[1])
 
for n in range(0,N):
    gcdd = gcd(gcdd,tousa[n])
    
print(gcdd)

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split(' '))
towns=list(map(int,input().split(' ')))
dists=[ abs(X-town) for town in towns ]
if N==1:
	print(dists[0])
else:
	ans=-1
	for i in range(N-1):
		if ans==-1:
			ans=fractions.gcd(dists[i],dists[i+1])
		else:
			ans=fractions.gcd(ans,dists[i])
	print(ans)

Submission status: Accepted

Solution code:
import sys

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return a


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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

length = []

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

ans = length[0]

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

print(ans)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = abs(L[i]-X)
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return x
cur = L[0]
for i in range(1,N):
  cur = gcd(L[i],cur)
print(cur)

Submission status: Accepted

Solution code:
from fractions import gcd

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

D = None
for x in xs:
    x = abs(x - X)
    if D is None:
        D = x
    else:
        D = gcd(D, x)

print(D)

Submission status: Accepted

Solution code:
from functools import reduce


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


def _gcd(*n):
    return reduce(gcd, n)


N, X = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(x + [X])
diff = [x[i+1] - x[i] for i in range(N)]
print(_gcd(*diff))

Submission status: Accepted

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

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

for i in range(N):
  tmp = abs(X-all_x[i])
  if(i == 0):
    ans = tmp
  else:
    ans = gcd(ans,tmp)
print(ans)

Submission status: Accepted

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


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


N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
GCD = abs(X-x[0])

for i in x:
    GCD = gcd(GCD, abs(X-i))

print(GCD)

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

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

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

def gcd(*numbers):
    return reduce(gcd_two, numbers)

#values
INF = 10**9

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

d_list = [abs(X-i) for i in x_list]
print(gcd(*d_list))

Submission status: Accepted

Solution code:
import fractions

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

d_ = list(set([x_[i+1]-x_[i] for i in range(N)]))

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

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

x.append(X)
x.sort()

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

print(gcd(*dist))

Submission status: Accepted

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

import fractions
from functools import reduce

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

print(gcd_list(d))

Submission status: Accepted

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

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

print(gcd(x))

Submission status: Accepted

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

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

if len(diff) >= 2:
    gcd_val = diff[0]
    for i in diff[1:]:
        gcd_val = gcd(gcd_val,i)
    print(gcd_val)
else:
    print(diff[0])

Submission status: Accepted

Solution code:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return max(a, b)
    else:
        return gcd(b, a%b)

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

Submission status: Accepted

Solution code:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
it = iter(x)
value = x[0]
for i in it:
    value = gcd(value, i)
print(value)

Submission status: Accepted

Solution code:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = reduce(gcd, x)
print(l)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
from functools import reduce
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)


N, X = MI()
x = LI()
diff = [abs(X - i) for i in x]
print(GCD_LIST(diff))

Submission status: Accepted

Solution code:
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()))

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

D = x2[0]
for i in range(N-1):
    D = gcd(D, x2[i+1])

print(D)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

#差の最大公約数を取得
gcd_val = diff[0]
for i in diff[1:]:
    gcd_val = gcd(i,gcd_val)

print(gcd_val)

Submission status: Accepted

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

import sys
input = sys.stdin.readline
N, S = map(int, input().split())
X = list(map(int, input().split()))
if N > 1:
    D = gcd(abs(X[0] - S), abs(X[1] - S))
    for x in X[2:]:
        D = gcd(abs(S - x), D)
    print(D)
else:
    print(abs(S - X[0]))

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator

from fractions import gcd


inf = float('inf')


# globals
N, X = 0, 0
C = []


def set_inputs():
    global N, X, C
    N, X = get_li()
    C = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = reduce(gcd, filter(lambda x: x != 0, map(lambda x: abs(x-X), C)))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce
import fractions

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

distance = [abs(X-xn[i]) for i in range(N)]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(distance))

Submission status: Accepted

Solution code:
import fractions as f
from functools import reduce
def gcd(nums):
    return reduce(f.gcd,nums)

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

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)
def gcd(p,q):
  if q==0:
    return p
  else:
    return gcd(q,p%q)
stack=X[0]
for i in range(n-1):
  stack=gcd(stack,X[i+1])
print(stack)

Submission status: Accepted

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

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

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

Submission status: Accepted

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

def gcd(x):
    if len(x) == 1:
        return x[0]
    m = min(x)
    return gcd([m]+[y%m for y in x if (y%m)>0])

print(gcd(x))

Submission status: Accepted

Solution code:
import fractions

N,X = (int(x) for x in input().split())
x = [int(p) for p in input().split()]
x.append(X)
x.sort()
D = x[1] - x[0]

for i in range(1,N):
    D = fractions.gcd(D,x[i+1]-x[i])

print(D)

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

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = gcd(ans,x[i+1]-x[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 = list(map(int,input().split()))
x.append(X)
x.sort()
x = [x[i]-x[0] for i in range(n+1)]
del x[0]
g = x[0]
for i in range(1, n):
    g = gcd(g,x[i])
print(g)