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

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

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
      
distance = [0] * N
diffs = [0] * (N-1)
for i in range(len(x)):
  distance[i] = abs(x[i] - X)
  if i > 0:
    diffs[i-1] = x[i] - x[i-1]

if N == 1:
  print(distance[0])
  sys.exit()
else:
  nearest = min(min(distance), min(diffs))

divisor = make_divisor_list(nearest)

for item in divisor[::-1]:
  for d in distance:
    if d%item != 0:
      break
    print(item)
    sys.exit()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Accepted

Solution code:
import functools

def gcd(x,y):
    big = max(x,y)
    small = min(x,y)
    while small > 0:
        big, small = small, big % small

    return big

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

diffs = [abs(X - x) for x in xs]

print(functools.reduce(gcd,diffs))

Submission status: Accepted

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


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


def solve(N: int, X: int, x: "List[int]"):
    y = [abs(item-X) for item in x]
    ans = y[0]
    for a in y:
        ans = GCD(a, ans)

    print(ans)
    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())
x = list(map(int,input().split()))
x.append(X)
x.sort()
xdif = [x[i+1] - x[i] for i in range(N)]
minxdif = min(xdif)
divisor = []
i = 1
for i in range(1,int(minxdif**0.5) + 1):
    if minxdif % i == 0:
        divisor.append(i)
        if i != minxdif//i:
            divisor.append(minxdif//i)
divisor = sorted(divisor)[::-1]
flag = 0
for div in divisor:
    for dif in xdif:
        if dif % div != 0:
            flag = 1
    if flag == 0:
        print(div)
        break
    flag = 0

Submission status: Accepted

Solution code:
from fractions import gcd
import bisect

N, X = map(int, input().split())
x = [int(i) for i in input().split()]
a = x[-1]
x.append(a)
x.sort()
bisect.insort_left(x, X)
ans = 0
for y, z in zip(x[:-1], x[1:]):
    ans = gcd(ans, z-y)
print(ans)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, X = s_inpl()
x = inpl()

x_diff = [ abs(X - xi) for xi in x]

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

# リストnumbers最大公約数
def gcdlist(numbers):
    a = numbers[0]
    for i in range(len(numbers)):
        a = gcd(a, numbers[i])
    return a

print(gcdlist(x_diff))

Submission status: Accepted

Solution code:
from functools import reduce

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

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

def main():
    N, X = map(int, input().split(' '))
    x_n = list(map(int, input().split(' ')))

    x_n = sorted(x_n)
    x_n = [n - X for n in x_n] # スタートを0からに
    
    print(abs(gcd(x_n)))
    return

main()

Submission status: Accepted

Solution code:
N, X = [int(i) for i in input().split(' ')]
xs = [int(i) for i in input().split(' ')]

for idx in range(N):
	xs[idx] = abs(xs[idx]-X)

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

tmp = xs[0]
for idx in range(N-1):
	tmp = gcd(tmp, xs[idx+1])

print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def euclid(diff_list):
    n = len(diff_list)
    gcd_ = gcd(diff_list[0], diff_list[1])
    for i in range(2, n):
        gcd_ = gcd(gcd_, diff_list[i])
    return gcd_
def gcd(a, b):
    a_min, a_max = min(a,b), max(a,b)
    r = 1
    while (r != 0):
        r = a_max % a_min
        a_max, a_min = a_min, r
    return a_max

n, x = map(int, input().split())
x_list = [int(i) for i in input().split()]
x_list.append(x)
x_list = sorted(x_list)
diff_list = [x_list[i+1] - x_list[i] for i in range(len(x_list)-1)]
if n > 1:
    ans = euclid(diff_list)
    print(ans)
else:
    ans = abs(x_list[0] - x_list[1])
    print(ans)

Submission status: Accepted

Solution code:
import fractions
import sys
from functools import reduce
readline = sys.stdin.readline

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

a = list(map(int, readline().split()))
N = a[0]
X = a[1]
city = list(map(int, readline().split()))

cnt = 0
for i in range(N):
    city[i] -= X
    if city[i] < 0:
        city[i] = 0 - city[i]

print(str(gcd(*city)))

Submission status: Accepted

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

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

if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])

answer=1
if N==1:
    answer=distance[0]
else:
    element = gcd(distance[0], distance[1])
    if N==2:answer=element
    else:
        for i in range(2,N):
            element=gcd(element,distance[i])
        answer=element

print(answer)

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

def main():
    ds = list(map(lambda n: abs(X - n), P))
    ans = reduce(lambda a, b: gcd(a, b), ds)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

difs = []
for i in range(len(x)-1):
    difs.append(x[i + 1] - x[i])
  
min_dif = min(difs)
divisors = sorted(make_divisors(min_dif))[::-1]

for divisor in divisors:
    flag = False
    for dif in difs:
        if dif % divisor != 0:
            flag = True
            break
    if flag == False:
        print(divisor)
        break

Submission status: Accepted

Solution code:
import fractions
nx=input().split()
N=int(nx[0]);X=int(nx[1])
xs=input().split()
xs=[int(x) for x in xs]
xs.append(X)
xs.sort()
n=xs[0]
xs.remove(n)
t=[]
for i in xs:
    t.append(i-n)
    n=i
count=t[0]
t.remove(count)
for j in t:
    count=fractions.gcd(count,j)
print(str(count))

Submission status: Accepted

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

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

d = -1
for x_str in input().split():
    x = int(x_str)
    dx = abs(X-x)
    if d == -1:
        d = dx
        continue
    d = gcd(d, dx)

print(d)

Submission status: Accepted

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

n,x=map(int,input().split())
x_lst=list(map(int,input().split()))
x_lst=list(map(lambda a:abs(a-x),x_lst))
print(gcd_list(x_lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
N, o = list(map(int, input().split()))
X = list(map(int, input().split()))
X = sorted(X)
X = [abs(x-o) for x in X]
# 最大公約数が答え
print(reduce(fractions.gcd, X))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

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

n = min(positions_from_X)

if N==1:
    flg = n
else:
    for d in sorted([i for i in range(1,n+1) if n%i==0], reverse=True):
        flg = d
        for p in positions_from_X:
            if p%d !=0:
                flg=0
                break
        if flg:
            break

print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
if n==1:
  print(abs(x-int(input())))
  exit()
l=list(map(int,input().split()))
l.append(x)
l.sort()
l2=[]
for i in range(1,n+1):
  l2.append(l[i]-l[i-1])
a=10000000000
for i in range(len(l2)-1):
  b=fractions.gcd(l2[i],l2[i+1])
  if b<a:
    a=b
print(a)

Submission status: Accepted

Solution code:
import fractions

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

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

print(ans)

Submission status: Accepted

Solution code:
n,cx=map(int,input().split())#city_num,default_location
x=list(map(int,input().split()))
x.sort()
"""
#1
#if cx<=x[0] or cx>=x[-1]:
a=abs(cx-x[0])
b=abs(cx-x[-1])

c=abs(x[0]-x[-1])
d=(min(a,b)+c)
print(d)
#elif x[0]<cx and cx<x[-1]:
"""
def gcd(cx,cy):
    if cy==0:
        return cx
    else:
        return gcd(cy,cx%cy)

d_l=[]
for l in x:
    d_l.append(abs(l-cx))
#print(d_l)
comp=d_l[0]

    
for i in range(0,len(d_l)):
    comp=gcd(d_l[i],comp)

print(comp)

Submission status: Accepted

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

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
for i in range(N):
    Di.append(abs(X - Xi[i]))
DLen = len(Di)
g = Di[0]
for i in range(1, DLen):
    if Di[i] != 0:
        g = gcd(g, Di[i])
print(g)

Submission status: Accepted

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    # if x%y:
    #     while x%y:
    #         z = x%y
    #         x, y = y, x
    #     else:
    #         return z
    # else:
    #     return y
    if y == 0:
        return x
    else:
        return gcd(y, x%y)


x.append(X)
x.sort()
# print(x)
# d = []
# for i in range(N):
#     d.append(x[i+1]-x[i])
# print(d)
for i in range(N):
    if i == 0:
        c = x[i+1]-x[i]
    else:
        c = gcd(x[i+1]-x[i], c)
print(c)

Submission status: Accepted

Solution code:
n, x = (int(i) for i in input().split()) 
a = sorted(list(set([int(i) for i in input().split()])))

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

import functools

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

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

list_gcd = functools.reduce(gcd, diff)

import bisect

bi_index = bisect.bisect_left(a, x)
if bi_index == len(a):
    print(gcd(list_gcd, x-a[-1]))
    exit()

if a[bi_index] == x:
    print(list_gcd)
    exit()

if bi_index == 0:
    print(gcd(list_gcd, a[0]-x))
    exit()

print(functools.reduce(gcd, [list_gcd, x-a[bi_index-1], a[bi_index]-x ]))

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
N , X = map(int, input().split())
xn = np.array(list(map(int,input().split() )))
#print(xn)
xn = xn - X
#xn = xn - np.min(xn)
#print(xn)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
print(abs(reduce(gcd, list(xn))))

Submission status: Accepted

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

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

x = [abs(n-X) for n in x]
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(" ")))
xi=list(map(int,input().split(" ")))

xi_=list(map(lambda y:abs(y-x),xi))

i=0
while i<=n-2:
    while xi_[i]!=0 and xi_[i+1]!=0:
        (xi_[i],xi_[i+1])=(max(xi_[i],xi_[i+1])%min(xi_[i],xi_[i+1]),min(xi_[i],xi_[i+1]))
    i+=1

print(xi_[n-1])

Submission status: Accepted

Solution code:
# 最大公約数なきがするけど。
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

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

xs.append(X)
xs = sorted(xs)
if len(xs) == 2:
    print(abs(xs[0]-xs[1]))
else:
    diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] #差を取る
    gcd_min = gcd(diffs[0],diffs[1])
    for i in range(2,len(diffs)):
        gcd_min = gcd(gcd_min, diffs[i])

    print(gcd_min)

Submission status: Accepted

Solution code:
N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    min_x = min(x_ls)
    x_ls = [x % min_x for x in x_ls]
    if not any(x_ls):
        break
    x_ls = [x for x in x_ls if x != 0]
print(min_x)

Submission status: Accepted

Solution code:
from sys import stdin
from functools import reduce
# バージョン 3.4.X 以前
import fractions
# バージョン 3.4.X より 後
# import math

input = stdin.readline

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

xn = [abs(X - int(i)) for i in input().split()]


def main():
    print(reduce(fractions.gcd, xn))
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline


def gcd(a, b):
    result = a
    k = 0
    n = b

    while True:
        k = result % n
        result = n
        n = k
        if k == 0:
            break

    return result


def gcd_n(numbers):
    l = numbers[0]

    for i in range(len(numbers)):
        l = gcd(l, numbers[i])

    return l


def lcm(a, b):
    g = gcd(a, b)

    return a * (b / g)


def lcm_n(numbers):
    l = numbers[0]

    for i in range(len(numbers)):
        l = lcm(l, numbers[i])

    return l


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

xn = [abs(X - int(i)) for i in input().split()]


def main():
    print(gcd_n(xn))
    return


main()

Submission status: Accepted

Solution code:
from fractions import*;_,X,*x=map(int,open(0).read().split());s,*x=[abs(X-t)for t in x]
for t in x:s=gcd(s,t)
print(s)

Submission status: Accepted

Solution code:
from fractions import*;from functools import*;n,x,*a=map(int,open(0).read().split());print(reduce(gcd,[abs(x-i)for i in a]))

Submission status: Accepted

Solution code:
from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())
b=[abs(x-i)for i in a]
print(reduce(gcd,b))

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

for i in range(result+1, 0, -1):
    if all(x % i == 0 for x in X_diff):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()

#  N = 10**5
#  X = 10**9
#  X_list = [i for i in range(1, 10**5, 5)]

#  if N == 1:
#      print(abs(X_list[0] - 1))
#      exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [abs(j-i) for i, j in zip(X_list[:-1], X_list[1:])]
X_diff = list(set(X_diff))
#  result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

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

for i in range(len(X_diff)):
    #  print(i)
    if i == 0:
        result = X_diff[i]
        continue
    
    result = gcd(X_diff[i], result)
#  while True:
#      if all(x % result == 0 for x in X_diff):
#          result = i
#      else:
#          result = [i for i in range(result, 0, -1) if ]

print(result)

Submission status: Accepted

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

y = [abs(i-X) for i in x]
def gcd(a, b): # 最大公約数
    while b:
        a, b = b, a % b
    return a
print(reduce(gcd,y))

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

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

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

import functools
ans = functools.reduce(gcd, x)
print(ans)

Submission status: Accepted

Solution code:
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
N,X=map(int,input().split())
l=[int(x) for x in input().split()]
l.append(X)
l.sort()
ans=float("inf")
if N==1:
  ans=l[1]-l[0]
else:
  for i in range(N-1):
    ans=min(ans,gcd(l[i+1]-l[i],l[i+2]-l[i+1]))
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    return gcd(b, a % b)


def skip(N: int, X: int, x: list)->int:
    sorted_x = sorted([X] + x)
    dists = [sorted_x[i+1] - sorted_x[i] for i in range(len(x))]
    before = 0
    for d in dists:
        before = gcd(before, d)
    return before


if __name__ == "__main__":
    N, X = map(int, input().split())
    x = [int(s) for s in input().split()]
    ans = skip(N, X, x)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

#n = ip()                                     #入力整数1つ
n,x= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = abs(a[0]-x)
for i in range(1,n):
    s = fractions.gcd(s,abs(a[i]-x))
print(s)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n, X = map(int, input().split())
x = list(map(int, input().split()))
for i in range(len(x)):
    x[i] = abs(x[i] - X)

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

print(gcd_list(x))

Submission status: Accepted

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
for i in range(N):
    if g == 1:
        break
    g = gcd(g, abs(X-x[i]))

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N,D=map(int,input().split())
X=list(map(int,input().split()))
X=sorted(X+[D])
m=min(X)
s=[X[i]-m for i in range(1,len(X))]
print(reduce(gcd,s))

Submission status: Accepted

Solution code:
from fractions import gcd 
from functools import reduce 
def gcd1(l):
    return reduce(gcd, l)
n, x=map(int, input().split())
xi=[int(i) for i in input().split()]
d=[abs(xii-x) for xii in xi]
print(gcd1(d))

Submission status: Accepted

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

l = list(map(int,input().split()))
dis = []
for i in range(1,len(l)):
    dis.append(abs(l[i]-l[i-1]))

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

res = abs(x-l[0])

for d in dis:
    res = gcd(res,d)
print(res)

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd

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

diff = abs(x-X)
intermediate_gcd = diff[0]

for i in range(len(x)-1):
    intermediate_gcd = gcd(intermediate_gcd, diff[i+1])

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

y = list(map(lambda a: abs(a - X), x))
g = y[0]
for yy in y[1:]:
    g = gcd(g, yy)
print(g)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(abs(X[0]-x))
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Submission status: Accepted

Solution code:
import fractions
import functools

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

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

X.append(X0)
X.sort()
between = []
for i in range(N):
    sa = X[i+1] - X[i]
    between.append(sa)
print(gcd_list(between))

Submission status: Accepted

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

def gcd_list(a):
    l = len(a)
    if l == 1:
        return a[0]
    ans = gcd(a[0], a[1])
    for i in range(2, l):
        ans = gcd(ans, a[i])
    return ans

N,X=map(int,input().split())
x=list(map(int,input().split()))
x2=[abs(t-X) for t in x]
print(gcd_list(x2))

Submission status: Accepted

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


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

if n==1:
    a=int(input())
    print(abs(a-x))
    exit()
else:
    str=input()
    lst=str.split(" ")
    a=int(lst[0])
    b=int(lst[1])
    maxim=gcd(abs(a-x),abs(b-x))
    for i in range(2,n):
        c=int(lst[i])
        maxim=gcd(maxim,abs(c-x))
print(maxim)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

for i in range(n):
    S.append(abs(s[i]-s[i+1]))

MAX = reduce(gcd, S)

print(MAX)

Submission status: Accepted

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

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

cities.append(K)

cities.sort()

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

dif = []

for i in range(N):
	dif.append(cities[i+1] - cities[i])
    

if len(dif) == 1:
	x = dif[0]

else:
    
	x = gcd(dif[0],dif[1])

	for i in range(2,N):
		x = gcd(x,dif[i])

print(x)

Submission status: Accepted

Solution code:
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
D = min(collections.Counter(list(set([(y[i+1] - y[i]) for i in range(0, N) if (y[i+1] - y[i]) != 0]))).keys())
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Submission status: Accepted

Solution code:
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
z = [(y[i+1] - y[i]) for i in range(0, N) if (y[i+1] - y[i]) != 0]
z = list(set(z))
a = collections.Counter(z).keys()
D = min(a)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Submission status: Accepted

Solution code:
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
z = [(y[i+1] - y[i]) for i in range(0, N)]
zz = []
for i in range(0, N):
    if z[i] != 0 and not(z[i] in zz):
        zz.append(z[i])
a = collections.Counter(zz).keys()
D = min(a)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Submission status: Accepted

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

dx=[abs(X-i) for i in x]
l=len(dx)

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

if l==1:
    k=dx[0]
else:
    for i in range(l-1):
        if i==0:
            k=dx[0]
        k=gcd(k,dx[i+1])

print(k)