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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

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

Submission status: Accepted

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


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


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

          

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

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    return gcd(m,n%m)
n,X = LI()
x = LI()
x = [abs(i-X) for i in x]
for i in range(n):
    if i == 0:
        g = x[i]
    g = gcd(g,x[i])
print(g)

Submission status: Accepted

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

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

x.sort()
import numpy as np
x = np.array(x)
x -= X
print(abs(gcd(*x)))

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
def my_gcd(gap):
    n = len(gap)
    if n == 1:
        return gap[0]
    ret = gap[0]
    for i in range(1, n):
        ret = gcd(ret, gap[i])
    return ret

n, start = map(int, input().split())
a = list(map(int, input().split()))
gap = []
a.append(start)
a.sort()
for i in range(1, n + 1):
    gap.append(abs(a[i] - a[i - 1]))
# print(gap)
print(my_gcd(gap))

Submission status: Accepted

Solution code:
import functools
from fractions import gcd

n,x = map(int,input().split())
li = list(map(int,input().split()))
li2 = [abs(i-x) for i in li]
print(functools.reduce(gcd,li2))

Submission status: Accepted

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

x.append(X)
x=sorted(x)
gcd=x[1]-x[0]

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

# input
N, X = map(int, input().split())
Xi_list = list(map(int, input().split()))
Xi_list.append(X)

Asc_Xi_list = sorted(Xi_list, reverse=True)

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

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

Submission status: Accepted

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

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

base = abs(town[0]-x)
for i in range(0,n):
    if (base >= abs(town[i]-x)):
        base = gcd(base, abs(town[i]-x))
        
    else:
        base = gcd(abs(town[i]-x), base)
print(base)

Submission status: Accepted

Solution code:
from fractions import gcd
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = abs(s - x)
  else:
    d = gcd(d, abs(s-x))
print(d)

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

res = dist[0]
for i in range(len(dist)):
    res = gcd(res, dist[i])
print(res)

Submission status: Accepted

Solution code:
def main():
    import fractions
    from functools import reduce

    n, x, *l = map(int, open(0).read().split())
    a = list(map(lambda i: abs(i-x), l))
    ans = reduce(fractions.gcd, a)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions as fr

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

a.append(y)

ans=abs(a[0]-a[1])

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

Submission status: Accepted

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


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

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

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

print(X[-1])

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
def u(o,p):
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    return c[1]
    
if 4 >= len(x_list) >= 3:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  print(u(a[1],a[0]))

elif len(x_list) > 4:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  u = u(a[1],a[0])
  for i in a:
    if i/u == int(i/u):
      pass
    else:
      u = i%u
  print(u)
else:
  print(x_list[1]-x_list[0])

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

Submission status: Accepted

Solution code:
import fractions
import functools

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

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

#print(x)

g=functools.reduce(fractions.gcd, x)

print(g)

Submission status: Accepted

Solution code:
# Problem C - Skip

from fractions import gcd

# input
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.append(X)
x_list = sorted(x_list)

# initialization
min_d = float('INF')
d_list = [0] * N
for i in range(N):
    d_list[i] = x_list[i+1] - x_list[i]
if len(d_list)==1:
    min_d = d_list[0]
else:
    for i in range(N-1):
        d_1 = d_list[i]
        d_2 = d_list[i+1]
        gcd_d = gcd(d_1, d_2)
        min_d = min(min_d, gcd_d)

# output
print(min_d)

Submission status: Accepted

Solution code:
from fractions import *
n,*a=map(int,open(0).read().split())
a.sort()
b=[i-j for i,j in zip(a[1:],a)]
c=b[0]
for i in b:
    c=gcd(i,c)
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def main():
    n,x = map(int,input().split())
    x_s = [int(i) for i in input().split()]
    x_s = sorted(x_s)
    diffs = []
    for i in x_s:
        diffs.append(abs(x-i))
    print(reduce(gcd,diffs))





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import numpy as np

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 = list(map(int, input().split()))
x = (list(map(int, input().split())))
x.sort()
bisect.insort_left(x, X)
x_diff = np.diff(x)

print(gcd_list(x_diff))

Submission status: Accepted

Solution code:
#C - Skip
N,X = map(int, input().split())
a =list(map(int, input().split()))
a.append(X)
a = sorted(a,reverse=True)
b =[]
for i in range(N):
    b.append(a[i]-a[i+1])

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

diff = [abs(_x - X) for _x in x]
ans = diff[0]
for d in diff:
  ans = gcd(ans, d)

print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a_abs = []
for i in range(n):
    a_abs.append(abs(a[i]-x))

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

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

Submission status: Accepted

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

lst.append(x)
lst.sort()
# print(lst)

dif = [0]*n
for i in range(n):
    dif[i] = lst[i+1]-lst[i]

print(gcd_list(dif))

Submission status: Accepted

Solution code:
from functools import reduce
import fractions

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

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

delta = []

for i in x:
    delta.append(abs(X-i))
    
print(gcd_list(delta))

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
from fractions import gcd
# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = list(map(int,readline().split()))
    city = list(map(int,readline().split()))

    diff = [abs(city[i] - x) for i in range(n)]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n, x = map(int, input().split())
list_X = list(map(int, input().split()))
list_Y = []

for c in list_X:
    list_Y.append(abs(c-x))

ans = list_Y[0]

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

print(ans)

Submission status: Accepted

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

N, X = map(int, input().split())
x = list(map(int, input().split()))
d = [0]*N
for i in range(N):
    d[i] = abs(x[i]-X)
ans = functools.reduce(lambda a,b: fractions.gcd(a,b), d)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import fractions # Atcoderではfractions


N, X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x = sorted(x)
y = [0] * (N)

for i in range(N):
    y[i] = x[i+1]-x[i]

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

Submission status: Accepted

Solution code:
import fractions

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

xlist2=[]
for i in range(N):
  xlist2.append(abs(xlist[i]-X))
  
#print(xlist2)
answer=xlist2[0]
for i in range(1,N):
  answer=fractions.gcd(answer,xlist2[i])
  
print(answer)

Submission status: Accepted

Solution code:
# a, bの最大公約数を返す関数
def GCD(a, b):
    if (b == 0):
        return a
    else:
        return GCD(b, a % b)


if __name__ == "__main__":
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    res = 0
    for i in range(N):
        res = GCD(res, abs(x[i] - X))
    print(res)

Submission status: Accepted

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

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

res = 0
for i in x_list:
    res = gcd(res, abs(x-i))

print(res)

Submission status: Accepted

Solution code:
import copy
from fractions import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))
z=copy.deepcopy(x)+[X]
z.sort()

if N>1:
  y=[0]*N
  for i in range(N):
    y[i] = z[i+1]-z[i]
  ans=y[0]
  for j in range(N):
    ans = gcd(y[j],ans)
  print(ans)
else:
  print(abs(X-x[0]))

Submission status: Accepted

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

d = abs(x - l[0])
for i in l[1:]:
    d = fractions.gcd(d, abs(x - i))
print(d)

Submission status: Accepted

Solution code:
from fractions import gcd    # 最大公約数: gcd(x, y)
from functools import reduce
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

    for i in range(n):
        num_list[i] = abs(num_list[i] - x)

    print(gcd_list(num_list))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions
n, X = map(int,input().split())
x = [int(i) for i in input().split()] 

GCD = abs(x[0] - X)
for i in range(1, n):
    GCD = fractions.gcd(GCD, abs(x[i] - X))
    #print(GCD)
print(GCD)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, x = MAP()
xx = LIST()
xx = [xx[i] - x for i in range(n)]
d = abs(xx[0])
for i in range(1, n):
    d = gcd(d, abs(xx[i]))
print(d)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
new_lst=[abs(i-x) for i in a]

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

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

print(ans)

Submission status: Accepted

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

l=list(map(int,input().split()))
l.append(x)
l=sorted(l)
ll=[]
for j in range(1,len(l)):
    ll.append(l[j]-l[j-1])
a=ll[0]
ans=0
if len(ll)==1:
    print(ll[0])
    exit()
else:
    for i in range(1,len(ll)):
        ans=fractions.gcd(a,ll[i])
        a=ans
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
lst=list(map(int,input().split()))
new_lst=[abs(i-x) for i in lst]

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

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd(*new_lst))

Submission status: Accepted

Solution code:
import math
import fractions
from functools import reduce

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

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

pos.append(x)
pos.sort()

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

print(gcd_list(dist))

Submission status: Accepted

Solution code:
from collections import deque
from fractions import gcd
import functools
n, x = map(int, input().split())
xl = list(map(int, input().split()))

xl.append(x)
xl.sort()

l = deque()
for i in range(n):
    l.append(xl[i+1] - xl[i])

l = list(set(l))
ans = functools.reduce(gcd, l)
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

n,X = map(int,input().split())
x = list(map(int,input().split()))
if n == 1:
	print(abs(X-x[0]))
	exit()
x.append(X)
n += 1
y = sorted(x)
y1 = y[0]
def gcd(a,b):
	if b == 0:
		return a
	else:
		return gcd(b,a%b)
for i in range(n):
	y[i] = y[i] - y1

li = gcd(y[0],y[1])
i = 1
d = deque()
d1 = deque()
while i * i <= li:
	if li%i == 0:
		d.append(i)
		d1.appendleft(li//i)
	i += 1
d.extend(d1)
#print(d)
for i in range(2,n):
	while y[i]%d[-1] != 0:
		d.pop()
	if d[-1] == 1:
		break	



print(d[-1])
#print(y)

Submission status: Accepted

Solution code:
import functools
N,X = map(int,(input().split()))
x =  list(map(lambda a:abs(int(a)-X),(input().split())))
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)
print(gcd(x))

Submission status: Accepted

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

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


from fractions import gcd
if len(arr) >= 2:
    k = gcd(arr[0], arr[1])
    for i in range(1,N):
        k = gcd(k, arr[i])
    print(k)

else:
    print(arr[0])

Submission status: Accepted

Solution code:

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

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2

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

for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = gcd(ans, tmp)
    ix += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import fractions
import functools
N, X = map(int, input().split())
x = np.array(sorted(list(map(int, input().split()))))
x =  np.insert(x, np.where(x > X)[0][0], X) if len(np.where(x > X)[0]) > 0 else np.append(x, X)
x = np.diff(x)
print(functools.reduce(fractions.gcd, x))

Submission status: Accepted

Solution code:
import fractions

n, x_start = map(int, input().split())
*x, = map(int, input().split())
x = [abs(x[i] - x_start) for i in range(n)]
ans = x[0]
for xi in x:
    ans = fractions.gcd(ans, xi)
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

ans=li[0]
for i in range(n):
    ans=fractions.gcd(ans,li[i])
print(ans)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

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

    from functools import reduce
    from fractions import gcd
    S=[0]*N
    for i in range(N):
        S[i]=X[i+1]-X[i]
    print(reduce(gcd,S) if N>1 else S[0])

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Accepted

Solution code:
from fractions import gcd 

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

print(ans)

Submission status: Accepted

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

x.append(X)
x.sort()

from fractions import gcd

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

print(ans)

Submission status: Accepted

Solution code:
def euclid(x, y):
    if(y != 0):
        tmp = y
        y = x % tmp
        x = tmp
        return euclid(x,y)
    else:
        return x
    
def main():
    N, X = map(int, input().split())
    x= list(map(int, input().split()))
    
    if(N > 1):
        D = 10**10
        for i in range(1, N):
            D = min(D, euclid(abs(x[i]-X), abs(x[i-1]-X)))     
        print(D)
    else:
        ans = abs(x[0]-X)
        print(ans)
main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

ls = []
xx.sort()


for s in xx:
    diff = abs(x-s)
    ls.append(diff)


def gcd_ls(num):
    return reduce(gcd, num)


print(gcd_ls(ls))

Submission status: Accepted

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

ns = list(map(lambda n: abs(n - x), xs))


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

result = ns[0]
for i in range(1, n):
    if result > ns[i]:
        result = gcd(result, ns[i])
    else:
        result = gcd(ns[i], result)

print(result)

Submission status: Accepted

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

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

    ans = 0
    for i in x:
        ans = GCD(ans, abs(X - i))
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n,x = map(int,input().strip().split())
    a = list(map(int, input().strip().split()))

    a=[y-x for y in a]
    print(abs(find_gcd(a)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

def main():
    n, X = map(int, input().split())
    x = list(map(lambda x: abs(int(x) - X), input().split()))

    M = x[0]

    for i in x[1:]:
        M = gcd(M, i)

    print(M)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from fractions import gcd


def main():
    n, X = map(int, input().split())
    x = np.array(list(map(int, input().split())))
    x -= X

    x = np.abs(x)

    M = x[0]

    for i in x[1:]:
        M = gcd(M, i)

    print(M)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#starting from X is equivalent to go to x1-X,x2-X,... starting from 0.
#donc x1-X est multiple de D, x2-X l'est aussi...donc gcd des xi-X.
import fractions
from functools import reduce
N,X = map(int,input().split())
L = [abs(i-X) for i in map(int,input().split())]
def gcd_list(numbers):
  return reduce(fractions.gcd,numbers)
print(gcd_list(L))

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[abs(x-i) for i in a]
from fractions import gcd
def lcm(x,y):
  return x * y // gcd(x,y)
def list_lcm(list):
  c=1
  for i in list:
    c=lcm(c,i)
  return c
def list_gcd(list):
    c=list[0]
    for i in list:
        c=gcd(c,i)
    return c
print(list_gcd(b))

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
x = list(map(int,input().split()))
le = []
x.append(m)
x.sort()

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
   
for i in range(n):
    le.append(x[i+1] - x[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n,m = input_list()
  x = input_list()
  if len(x) == 1:
    print(abs(x[0] - m))
    exit(0)
  diffs = []
  for i in range(len(x)):
    d = abs(m - x[i])
    diffs.append(d)
  print(gcd_list(diffs))
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

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

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
b = list(sorted(x))
c = list()
for i in range(N):
    c.append(b[i+1]-b[i])

t = 0
for i in range(N):
    t = fractions.gcd(t, c[i])
print(t)

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
b = list(sorted(x))
c = list()
for i in range(N):
    c.append(b[i+1]-b[i])

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n, x, *X = map(int, open(0).read().split())
X = sorted(X + [x])

Y = [x1-x0 for x0, x1 in zip(X, X[1:])]
print(reduce(gcd, Y))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted([abs(i-x) for i in l],reverse=True)

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

if n!=1:
    p=gcd(l[0],l[1])
    for i in l[2:]:
        p=gcd(i,p)
else:
    p=l[0]
print(p)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted([abs(i-x) for i in l],reverse=True)

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

if n!=1:
    p=gcd(l[0],l[1])
    for i in l[2:]:
        q=gcd(i,p)
        p=q
else:
    p=l[0]
print(p)