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 sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


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

def gcd_(list):
    result = list[0]
    for el in list[1:]:
        result = gcd(result, el)
    return result


n, x = LI()
X = LI()

X.append(x)
X.sort()

X_ = [post - pre for pre, post in zip(X[:-1], X[1:])]

print(gcd_(X_))

Submission status: Accepted

Solution code:

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


N, X = [int(c) for c in raw_input().split()]
xs = [int(c) for c in raw_input().split()]

if len(xs) == 1:
    print abs(xs[0]-X)
else:
    xs.sort()
    d_min = xs[-1]-xs[0]

    if X < xs[0]:
        d_min = min(d_min, xs[0]-X)
    elif X > xs[-1]:
        d_min = min(d_min, X-xs[-1])

    for i in range(len(xs)-1):
        if xs[i] < X < xs[i+1]:
            d_min = gcd(d_min, X-xs[i])
            d_min = gcd(d_min, xs[i+1]-X)
            continue
        d_min = gcd(d_min, xs[i+1] - xs[i])
    print d_min

Submission status: Accepted

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

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

city = input().split(" ")

kouyaku = abs(int(city[0]) - X)

for i in range(N):
  kouyaku = gcd(kouyaku,abs(int(city[i]) - X))
  
print(kouyaku)

Submission status: Accepted

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

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

xl.append(x)
xl.sort()
xl.reverse()

_d = []
d = 1

for i in range(n):
    if i == n:
        break

    _d.append(xl[i] - xl[i + 1])

for i in range(2, min(_d) + 1):
    for j in _d:
        if j % i != 0:
            break
    else:
        d = i

print(d)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 109 20180908
# Question:C 全ての都市間の最大公約数を求める

#二つの数の最大公約数
def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)
 

init = input().split(" ")
init = [int(c) for c in init]

nums = input().split(" ")
nums = [int(c) for c in nums]

if not init[1] in nums:
	nums.append(init[1])
nums.sort()

d = max(nums) - min(nums)

for j in range(1, init[0]):
	d1 = nums[j] - nums[j-1]
	d2 = nums[j+1] - nums[j]

	d = min(gcd(d1,d2), d)
	if d == 1:
		break
print(d)

Submission status: Accepted

Solution code:
import math
from functools import reduce
import fractions
import sys


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


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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False

odds = list()

for i in range(n):
    diff = zahyo[i+1] - zahyo[i]

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True
        odds.append(diff)

    if diff < min:
        min = zahyo[i+1] - zahyo[i]

# print(is_odd)
# print(is_even)
if is_odd == True and is_even == True:
    print(1)
    sys.exit()

elif is_odd == True:
    print(gcd(*odds))
else:

    print(min)

Submission status: Accepted

Solution code:
# abc109c

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


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


n, x = [int(_) for _ in input().split()]
x_list = [int(_) for _ in input().split()]

list = [abs(x_list[i] - x) for i in range(n)]

answer = gcd_list(list)
print(answer)

Submission status: Accepted

Solution code:
import fractions


def run(n, x, xx):
    xx.append(x)
    xx = sorted(xx)
    d = [xx[i+1]-xx[i] for i in range(n)]
    d = sorted(d)
    min_d = d[0]
    if len(d) == 1:
        pass
    else:
        for i in range(1, len(d)):
            min_d = fractions.gcd(min_d, d[i])
    return min_d


def main():
    n, x = map(int, input().split())
    xx = list(map(int, input().split()))
    print(run(n, x, xx))


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()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=gcd(ans, abs(xi-X))
print(ans)

Submission status: Accepted

Solution code:
ini=map(int, raw_input().split())
list=map(int, raw_input().split())

list.append(ini[1])
list.sort()

sa=[]
for i in range(len(list) - 1):
    sa.append(list[i+1]-list[i])
while True:
    sa.sort()
    amari=[]
    ch=0
    for i in range(len(sa)):
        ama=sa[i]%sa[0]
        if ama==0:
            amari.append(sa[0])
        else:
            amari.append(ama)
            ch=1
    if ch==0:
        break
    else:
        sa=amari

sa.sort()
print(sa[0])

Submission status: Accepted

Solution code:
from sys import stderr
from functools import reduce
from operator import add
from bisect import insort
from fractions import gcd
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, x = f()
X = sorted(f())
insort(X,x)
dist = [X[i+1]-X[i] for i in range(n)]
print(reduce(gcd, dist))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

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


city_num, start_pos = list(map(int, input().split()))
city_list = list(map(int, input().split()))

# スタート位置を入れて
city_list.append(start_pos)
# 昇順に並び替え
city_list.sort()

# city毎の距離のリストを生成する
distance_list = [city_list[i+1] - city_list[i] for i in range(city_num)]

# 距離が一つならそれを出力
if len(distance_list) == 1:
    print(distance_list[0])
    exit()

# 昇順に並び替え
distance_list.sort()

# 最大公約数を求める
max_gcd = gcd(distance_list[0], distance_list[1])
for i in range(2, len(distance_list)):
    max_gcd = gcd(max_gcd, distance_list[i])

# 出力
print(max_gcd)

Submission status: Accepted

Solution code:
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    xxx = [x for x in xxx if x > 0]
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S, X):
    Xs = []
    for x in X:
        t = abs(x - S)
        Xs.append(t)

    if N == 1:
        return Xs[0]
    ans = gcd(Xs[0], Xs[1])
    for i in range(2, N):
        ans = gcd(ans, Xs[i])

    return ans


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


def main():
    N, S = read_int_n()
    X = read_int_n()
    print(slv(N, S, X))

    # N = 10000
    # S = random.randint(1, 10**9)
    # # X = [random.randint(1, 10**9) for _ in range(N)]
    # S = 1
    # X = list(range(N))
    # print(slv(N, S, X))


if __name__ == '__main__':
    main()

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()))
ans = abs(x[0] - X)

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

print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    a.append(x)
    a.sort()
    box = [a[i+1]-a[i] for i in range(n)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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

n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

dist_list.append(minimum)

print(gcd_list(dist_list))

Submission status: Accepted

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

diff = []
for i in range(len(x)-1):
    diff.append(x[i+1] - x[i])
#print("diff: ")
#print(diff)

base = min(diff)
for i in range(1, base+1):
    flag = True
    if base%i != 0:
        continue
    div = int(base/i)
    for j in range(len(diff)):
        if diff[j]%div != 0:
            flag = False
            break
    if flag == True:
        ans = div
        break

print(ans)

Submission status: Accepted

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

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

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

l = xx[0]
if len(xx) > 1:
    for i in xx[1:]:
        l = gcd(l, i)


print(l)

Submission status: Accepted

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

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

n, x = (int(i) for i in input().split())
xs = [int(i) for i in input().split()]
new_xs = []
for i in xs:
    new_xs.append(i-x)
print(abs(solve(*new_xs)))

Submission status: Accepted

Solution code:
from functools import reduce
import sys
n=list(map(int,input().split()))
a=list(map(int,input().split()))

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

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

for i in range(n[0]):
  a[i] -= n[1]

print(abs(gcd_list(a)))

Submission status: Accepted

Solution code:
import numpy as np

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
line = input().split()
N = int(line[0])
X = int(line[1])

line = input().split()

diff = [abs(int(x)-X) for x in line]

min_ = gcd(diff[0], diff[0])

for df in diff:
    min_ = min(min_, gcd(diff[0], df))

print(min_)

Submission status: Accepted

Solution code:
import fractions
data=map(int,raw_input().split())
x=map(int,raw_input().split())

x.append(data[1])
x.sort()

#print x
d=[]
for i in range(data[0]):
  d.append(x[i+1]-x[i])
#print d
print reduce(fractions.gcd,d)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

def solve():
  n, start = map(int, input().split())
  cities = input().split(" ")
  # Startを0からに変更
  cities = [int(i) - start for i in cities]
  print(abs(gcd(*cities)))

solve()

Submission status: Accepted

Solution code:
iN , iX = [int(x) for x in input().split()]
aX = [abs(int(x) - iX) for x in input().split()]
def gcd(a,b):
    return a if b == 0 else gcd( b, a % b)

if iN == 1 :
    print( aX[0] )
else:
    g = gcd(aX[0],aX[1])
    if 2 < iN :
        for i in range(2,iN):
            g = gcd(g,aX[i])
    print (g)

Submission status: Accepted

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

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = int(gcd(ans, dx))
elif len(x) == 2:
    ans = x[1] - x[0]


print(ans)

Submission status: Accepted

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

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

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

ret = x[0]- X

for num in x:
    ret = gcd(ret,num - X)

print(ret)

Submission status: Accepted

Solution code:
n,x =map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
b = []
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
for i in range(n):
  b.append(a[i+1]-a[i])
print(gcd_list(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, mx = map(lambda s: int(s), list(input().split()))
xs = map(lambda s: int(s), list(input().split()))

mn = 9999999999

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

for x in xs:
    d = abs(mx-x)
    if mn == 9999999999:
        mn = d
    else:
        mn = gcd(mn, d)
print(mn)

Submission status: Accepted

Solution code:
import functools
import math
import sys

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

array = list(map(int,input().split()))
N = array[0]
X = array[1]
array = list(map(int,input().split()))
if len(array) == 1:
  print(abs(array[0] - X))
  sys.exit()
array.append(X)
array.sort()
A = array[:array.index(X) + 1]
B = array[array.index(X):]
C = []
for i in range(1,len(A)):
  C.append(A[i] - A[i - 1])
for i in range(1,len(B)):
  C.append(B[i] - B[i - 1])

a = gcd(C[0],C[1])
for i in C:
  a = gcd(a,i)
print(a)

Submission status: Accepted

Solution code:
f = lambda: map(int,input().split())


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


n, X = f()
x = list(f())
ans = x[0]-X

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

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()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

print(reduce(gcd, dist))

Submission status: Accepted

Solution code:
def gcd(a,b):
    while a:
        a,b = b%a,a
    return b
    
a = input().split()
a = [int(i) for i in a]

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

output = lis[0] - a[1]
for i in range(len(lis)):
	lis[i] = lis[i] - a[1]
	output = gcd(output, lis[i])

print(abs(output))

Submission status: Accepted

Solution code:
import fractions
  

N, X = map(int, input().split())
town = list(map(int, input().split()))
 
for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X
  
gcd = town[0]
for i in range(1, N):
  gcd = fractions.gcd(gcd, town[i])
print(gcd)

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

x.append(X)
x=sorted(x)

diff=[]
ans=0

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


if N > 1:
    ans=gcd(diff[0],diff[1])
    for i in range(1,N):
        ans=gcd(ans,diff[i])
    print(ans)
else:
    print(diff[0])

Submission status: Accepted

Solution code:
import sys,collections,math,functools;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

n, s = Is()
xs = Is()
xs2 = [abs(e-s) for e in xs]
c = xs2[0]
ans = c
for e in xs2:
    ans = gcd(ans,e)
print(ans)

Submission status: Accepted

Solution code:
def gcd(A,B):
    deka = max(A,B)
    mini = min(A,B)
    
    while not deka % mini == 0:       
        yo = deka % mini
        deka = mini
        mini = yo
    return mini


DATA = input()

N,X = DATA.split()
N = int(N)
X = int(X)

DATA = input()
x = DATA.split()

x[0] = int(x[0])
num = abs(X-x[0])

for lop in range(1,N):
    x[lop] = int(x[lop])
    sa = abs(X-x[lop])
    num = gcd(num,sa)
print(num)

Submission status: Accepted

Solution code:
def main():
    N, X = map(int, raw_input().split())
    co = map(int, raw_input().split())
    D = 0
    for coo in co:
        dist = abs(coo - X)
        if D!=0:
            D = gcd(dist,D)
        else:
            D = dist
    print(D)

def gcd(a, b):
    """Calculate the Greatest Common Divisor of a and b.

    Unless b==0, the result will have the same sign as b (so that when
    b is divided by it, the result comes out positive).
    """
    while b:
        a, b = b, a%b
    return a

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
a,b=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
s=abs(x[-1]-b)
d=set()
for i in range(a-1):
    s=min(s,abs(x[i]-b))
    d.add(x[i+1]-x[i])
if a==1:
    print(abs(b-x[0]))
    exit()
ans=s
while d:
    ans=fractions.gcd(ans,d.pop())
print(ans)

Submission status: Accepted

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

NX = input()
N,X = NX.split()
N = int(N)
X = [int(X)]
indice = input()
x = indice.split()
for i in x:
    X.append(int(i))

Y = sorted(X)    
d = [i for i in range(N)]
for j in range(len(Y)-1):
    d[j] = Y[j+1]-Y[j]

if len(d)>2:
    f = gcd(d[0],d[1])
    for i in range(len(d)-2):
        f = gcd(f,d[i+2])
elif len(d)>1:
    f = gcd(d[0],d[1])
else: f = d[0]

print(f)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
y=list(map(int,input().split()))
y.append(x)
sorted(y)
a=y.index(x)
from fractions import gcd
from functools import reduce
def gcd_list(numbers):
    return reduce(gcd, numbers)
list=[]
for i in range(len(y)-1):
    list.append(abs(int(y[i])-int(y[i+1])))
print(gcd_list(list))

Submission status: Accepted

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

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

xx0 = [abs(xi-x0) for xi in x ]

y = xx0[0]
for yi in xx0:
    y = gcd(y, yi)
    
print(y)

Submission status: Accepted

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

N, X = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
ans = A[0] - X
for a in A:
    ans = gcd(ans, abs(a - X))

print (ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

for xi in xn:
    xn2.append(abs(xi - X))

xn2.sort()

gcd_num = max(xn2)
for xi2 in xn2:
    tmp = gcd(xi2,gcd_num)
    if tmp < gcd_num:
        gcd_num = tmp

print(gcd_num)

Submission status: Accepted

Solution code:
# problem C
n, x0 = (int(i) for i in input().split(' '))
x = (int(i) for i in input().split(' '))
d = list(map(lambda t: abs(t-x0), x))

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

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

print(g)

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
l=list(map(int,input().split()))
m=[];
for i in l:
  m.append(abs(i-x))
n=m.pop(0)
for j in m:
  n=fractions.gcd(n,j)
print(n)

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = x[1] - x[0]
    if mini > abs(X - x[0]) and abs(X - x[0]) != 0:
        mini = abs(X - x[0])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > x[i] - x[i - 1]:
        mini = x[i] - x[i - 1]
    if mini> abs(X - x[i]) and abs(X - x[i]) != 0:
        mini = abs(X - x[i])
    if (x[i] - x[i - 1]) % mini != 0:
        #break
        mini = fractions.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        #break
        mini = fractions.gcd(mini, X - x[i])
        

print(mini)

Submission status: Accepted

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

N, X = [int(n) for n in input().split()]
xs = [int(n) for n in input().split()]

xs.append(X)

m = min(xs)
xs = [n - m for n in xs]
g = gcd(max(xs[0], xs[1]), min(xs[0], xs[1]))
for n in xs[2:]:
    g = gcd(max(g, n), min(g, n))
print(g)

Submission status: Accepted

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


inputs = input().strip().split()

N  = int(inputs[0])
X  = int(inputs[1])

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

if N == 1:
    print(xi[0])
else:
    a = xi[0]
    b = xi[1]

    nx = gcd(a, b)

    for i in range(2, len(xi)):
        nx = gcd(nx, xi[i])     

    print(nx)

Submission status: Accepted

Solution code:
n, x0 = map(int , input().split())
x = list(map(int , input().split()))
x = {abs(xi - x0) for xi in x}
while x:
  d = min(x)
  x = {xi % d for xi in x if xi % d}
print(d)

Submission status: Accepted

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


N,X=map(int,input().split(" "))
xl=list(map(int,input().split(" ")))
xl.append(X)
xl=sorted(xl)

xx=[xl[i+1]-xl[i] for i in range(len(xl)-1)]

ans=max(xx)
for i in range(len(xx)):
    ans=gcd(ans,xx[i])

print(ans)

Submission status: Accepted

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

from functools import reduce

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

# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

print(gcd_list(xN2))

Submission status: Accepted

Solution code:
# coding: utf-8

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


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

x = map(int, raw_input().split())
x.append(X)
x = sorted(x)

A = [ abs(x[i+1] - x[i]) for i in range(N)]


for i in range(len(A)):
    if i == 0:
        ans = A[i]
    else:
        ans = gcd(ans, A[i])

print ans

Submission status: Accepted

Solution code:
def gcd(x, y):
    r = modlog(x, y)
    while r != 0:
        x = y
        y = r
        r = modlog(x, y)
    return y

def modlog(x, y):
    r = x % y
    return r

if __name__ == '__main__' :
    N,X = map(int, input().split())
    x = list(map(int, input().split()))

    dist_list = [abs(d-X) for d in x]

    if len(dist_list) == 1:
        print (dist_list[0])
        exit()
        
    alpha = gcd(dist_list[0],dist_list[1])
    for d in dist_list:
        alpha = gcd(alpha,d)

    print(alpha)

Submission status: Accepted

Solution code:
import fractions

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

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = fractions.gcd(g, xs[i])
    return g

print(listgcd(dist))

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(x, y):
    if not y:
        return x
    return gcd(y, x % y)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
d = []
for i in range(N):
    d.append(x[i + 1] - x[i])
ans = reduce(gcd, d)
print(ans)

Submission status: Accepted

Solution code:

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

def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    ans = min(dists)
    for d in dists:
        if d % ans == 0:
            continue
        else:
            ans = gcd(ans, d % ans)
    return ans

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Submission status: Accepted

Solution code:
from fractions import gcd

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



N, X = map(int, input().split())		# 5 7
A = list( map(int, input().split()) )	# 1 2 3 4 5 ...(ソート付き)

#print(A)

A = A + [X]
A.sort()

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

#print(A)
#print(B)


a = B[0]
for b in B:
	a = gcd(a, b)

print(a)
exit(0)

Submission status: Accepted

Solution code:
from fractions import gcd

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i + 1] - a[i] for i in range(n)]

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)

n,x= map(int,input().split())
a = input().rstrip().split()
b = [0]*n
# a
for i in range(0,n):
    b[i]=abs(int(a[i])-x)
b.sort()#昇順

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

def multi_GCD(le):
    # print(le)
    if len(le)==1:
        return
    mxle=le[-1]
    del(le[-1])
    le[-1]=GCD(le[-1],mxle)
    multi_GCD(le)

if(len(b)==1):
    print(b[0])
if(len(b)==2):
    print(GCD(b[0],b[1]))
if(len(b)>2):
    multi_GCD(b)
    print(b[0])

Submission status: Accepted

Solution code:

import sys


N,X=[int(i) for i in input().split(" ")]
x=[abs(int(i)-X) for i in input().split(" ")]
minimum=min(x)




yakusuu=[]
for i in range(1,minimum+1):
    if minimum%i==0:
        yakusuu.append(i)
        yakusuu.append(minimum//i)
    if (minimum/i)+1<i:
        break
yakusuu=sorted(yakusuu)[::-1]
for i in yakusuu:
    flag=True
    for j in x:
        if j%i!=0:
            flag=False
    if flag:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
import numpy as np

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

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

x = np.append(x, X)
x = np.sort(x)

d = np.diff(x)
h = d[-1]
for i in range(len(d)-1):
    h = gcd(h, d[i])

print(h)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Accepted

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

import fractions

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

a.sort()

res = 0
for val in a:
    if res == 0:
        res = val
    else:
        res = fractions.gcd(res, val)
        if res == 1:
            break

print(res)

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
a1 = input().split()
b = []
for i in range(N):
  b.append(abs(int(a1[i])-X))
z = b[0]
if N == 1:
  print(z)
else:
  for i in range(1,N):
    z = fractions.gcd(z,b[i])
  print(z)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

def factorize(x):
    fct = []
    fct2 = []
    if x == 1:
        fct.append(1)
        return fct
    b = 1
    while b * b <= x:
        if x%b == 0:
            fct.append(b)
            fct2.append(x//b)
        b += 1
    fct.extend(fct2[::-1])
    return fct

N, X = na()
xarr = np.array(na())

diff = np.abs(xarr - X)
min_d = diff.min()

fac = factorize(min_d)

for x in fac[::-1]:
    flag = 1
    for d in diff:
        if d % x != 0:
            flag = 0
            break
    if flag == 1:
        print(x)
        exit()

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
L = list(map(int, input().split()))
M = [abs(i-X) for i in L if i-X != 0]
n = len(M)
old = M[0]
def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    else:
        m = max(a, b)
        n = min(a, b)
        return gcd(n, m%n)
if n > 1:
    for i in range(n-1):
        new = M[i+1]
        old = gcd(old, new)
print(old)

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())
    x_list = list(map(int, input().split()))
    x_list.append(x)
    x_list.sort()
    diff = []
    for i in range(n):
        diff.append(x_list[i + 1] - x_list[i])
    print(gcd_list(diff))

if __name__ == '__main__':
    main()