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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
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)
  return divisors

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

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,x=map(int, input().split())
    l=list(map(int,input().split()))
    ll=[]
    for i in l:
        ll.append(abs(x-i))
    from functools import reduce
    from fractions import gcd
    print(reduce(gcd,ll))
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

from fractions import gcd # gcd(a, b) で a, b の最大公約数を求める

def gcds(List): #list[a[0], a[1], ... , a[n]]の最大公約数を求める
  if len(List) == 1:
    return List[0]
  ans = gcd(List[0], List[1])
  for i in range(2, len(List)):
    ans = gcd(ans, List[i])
  return ans

print(gcds(lst))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x < y:
        x,y = y,x
    
    while x%y != 0:
        x,y = y,x%y

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

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

l=[abs(i - X) for i in x]
ans=l[0]

if len(l) == 1:
    print(ans)
    exit()
    
for i in range(1,len(l)):
    ans = gcd(ans,l[i])
    
print(ans)

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
A=[]
for t in x:
    A.append(abs(t-X))
ans=A[0]
for s in A:
    ans=fractions.gcd(ans,s)
print(ans)

Submission status: Accepted

Solution code:
import sys, fractions

N, X = map(int, input().split())
x = list(map(int, sys.stdin.readline().rsplit()))

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

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

x_ = [abs(X - i) for i in x]
x_.sort(reverse=True)
D = x_[0]
for i in range(1, N):
  D = gcd(D, x_[i])
print(D)

Submission status: Accepted

Solution code:
import numpy as np


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


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

X = np.array([X])

x = np.concatenate([x, X])
x.sort(0)
x = np.abs(np.diff(x))

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

print(ans)

Submission status: Accepted

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

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

x2 = x.copy() + [X]
x2 = sorted(x2)
diffs = []
for i in range(1, len(x2)):
    diffs.append(x2[i] - x2[i - 1])
if len(diffs) == 1:
    print(diffs[0])
else:
    diffs_gcd = gcd(diffs[0], diffs[1])
    for i in range(2, len(diffs)):
        diffs_gcd = gcd(diffs_gcd, diffs[i])
    print(diffs_gcd)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
xlist = sorted(list(map(int, input().split()))+ [X])

import fractions
from functools import reduce


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


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
sbn = [xlist[i+1] - xlist[i] for i in range(N)]
print(gcd_list(sbn))

Submission status: Accepted

Solution code:
from fractions import gcd
n,x=map(int,input().split())
X=list(map(int,input().split()))
res=abs(X[0]-x)
 
for y in X:
	res=gcd(res,abs(y-x))
	
print(res)

Submission status: Accepted

Solution code:
from fractions import gcd

n,x = map(int,input().split())
x_list = list(map(int,input().split()))
hoge = set()
for y in x_list:
  hoge.add(abs(x-y))
ans = abs(x_list[0]-x)
for num in hoge:
  ans = gcd(num,ans)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

ans = S[0]
for i in range(1, N):
    ans = gcd(ans,S[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 pos in x:
    ans = fractions.gcd(ans, abs(X-pos))

print(ans)

Submission status: Accepted

Solution code:
n, s = map(int, input().split())
lis = list(map(int, input().split()))
lis.append(s)
lis.sort()


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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, start = Is()
X = LI()
m = min(X+[start])
ans = reduce(gcd, [x-m for x in X+[start]])
print(ans)

Submission status: Accepted

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

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

x=[]
for _ in input().split():
    x.append(int(_))

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

if len(dist)>1:
    D=gcd(dist[0],dist[1])
    for i in range(len(dist)):
        D=gcd(D,dist[i])
else:
    D=dist[0]

print(D)

Submission status: Accepted

Solution code:
import fractions
a,b= list(map(int, input().split()))
i= list(map(int, input().split()))

ans=0
l=[]
for j in range(a):
    l.append(abs(b-i[j]))
for k in range(0,a):
    if k==0:
        ans=l[0]
    else:
        ans=fractions.gcd(ans,l[k])
print(ans)

Submission status: Accepted

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

x.append(start)
x.sort()

distance = []
for i in range(n):
    dis = abs(x[i+1] - x[i])
    distance.append(dis)
if len(distance) == 1:
    D = distance[0]
else:
    D = gcd(distance[0], distance[1])
    for i in range(2, n):
        D = gcd(D, distance[i])
print(D)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions,itertools
N,S = [int(hoge) for hoge in input().split()]
X = [int(hoge) - S for hoge in input().split()]
print(abs(list(itertools.accumulate(X,func = fractions.gcd))[-1]))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N,X = (int(x) for x in input().split())
x = list(map(int, input().split()))
a = [abs(X-y) for y in x]
if N == 1:
    print(a[0])
else:
    gcd = xgcd(a[0],a[1])
    for i in range(2,N):
        gcd = xgcd(gcd,a[i])
    print(gcd)

Submission status: Accepted

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

#各都市の移動距離を求め、そのgcd
x_input.append(x)
x_li = sorted(x_input)

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

g = cost_li.pop(0)
for c in cost_li:
    g = math.gcd(g,c)

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd

n, x = map(int, input().split())
a = [abs(int(A) - x) for A in input().split()]
a.sort()
print(reduce(gcd, a))

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    A,B=pin()
    X=lispin()
    temp=abs(B-X[0])
    for x in X:
        temp=gcd(temp,abs(B-x))
    print(temp)
    
#%%submit!
resolve()

Submission status: Accepted

Solution code:
from fractions import gcd  # for python3.5~ use math.gcd


def main():
    N, X = list(map(int, input().split(' ')))
    x_list = list(map(lambda x: abs(int(x) - X), input().split(' ')))
    ans = x_list[0]
    for x in x_list[1:]:
        ans = gcd(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

Solution code:
"""
マスターオブ整数
"""
import fractions

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

dist = [abs(i - X) for i in cities]
division = dist[0]
for i in dist[1:]:
    division = fractions.gcd(division, i)

print(division)

Submission status: Accepted

Solution code:
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(a[0]-x)
for i in range(n):
    ans = fractions.gcd(ans, abs(a[i]-x))
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

    ans = []
    for i in l:
        ans.append(abs(x-i))

    return gcd_list(ans)
    

print(solve())

Submission status: Accepted

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

if len(y) == 1:
    print(abs(y[0]))
    exit()

import fractions
d = fractions.gcd(y[0], y[1])
for xi in y:
    d = fractions.gcd(d, xi)
print(abs(d))

Submission status: Accepted

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

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

'''
A=[]
B=[]
for i in range():
    a,b = map(int, input().split())
    x=
    A.append(a)
    B.append(b)'''

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

def yakusuu(n):
    #約数リスト生成,バラバラに出るので.sort()を使う必要あるかも
    #PyPy推奨
    yakusuu_list = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yakusuu_list.append(i)
            if i != n // i:
                yakusuu_list.append(n//i)
    return yakusuu_list
#print(sa)
slis=yakusuu(min(sa))
slis.sort()
#print(slis)
for item in slis:
    cnt=0
    for i in range(n):
        if sa[i]%item==0:
            cnt+=1
    if cnt==len(x):
        maxx=item
print(maxx)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

n,x=MI()
lis=LI()
for i in range(n):
    lis[i]=abs(lis[i]-x)
if n==1:
    print(lis[0])
    sys.exit()
a=lis[0]
b=lis[1]
for i in range(2,n):
    a=gcd(a,b)
    b=lis[i]
print(gcd(a,b))

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
L = sorted(list(map(int, input().split())))

ans = abs(L[0]-X)
for x in L[1:]:
    ans = gcd(ans, abs(x-X))
print(ans)

Submission status: Accepted

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

for y in X:
	res=gcd(res,abs(y-x))
	
print(res)

Submission status: Accepted

Solution code:
#import math
import fractions
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,x = iim()
xmod = list(map(lambda y:abs(int(y)-x),input().split()))
#print(xmod)
gcd = xmod[0]
for i in xmod:
    gcd = fractions.gcd(gcd,i)

print(gcd)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X0 = lr()
X = np.array(lr())
Xdiff = np.abs((X-X0)).tolist()
g = Xdiff[0]
for i in range(1, N):
    g = gcd(g, Xdiff[i])

answer = g
print(answer)

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd
from functools import reduce
N, x = map(int, input().split())
X = np.array(list(map(int, input().split())) + [x], dtype=np.int32)
X.sort()
X -= X[0]
print(reduce(gcd, X))

Submission status: Accepted

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

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

N, X = map(int, input().split())
x = np.array(list(map(int, input().split())))
if N == 1:
    print(np.abs(x[0] - X))
else:
    x = np.abs(x - X)
    print(gcd(x))

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, x = mi()
    L = list(map(lambda point: abs(int(point) - x), input().split()))
    g = L[0]
    for i in range(1, n):
        g = gcd(g, L[i])
    print(g)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

lis=[]
for i in range(0,n):
  lis.append(abs(x[i]-k))

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  cc=aa%bb
  aa=bb
  bb=cc
  if bb!=0:
    return gcd(aa,bb)
  else:
    return aa

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

Submission status: Accepted

Solution code:
# AtCoder
from fractions import gcd
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
    x[i] = abs(x[i]-X)
ans = reduce(gcd, x)
print(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()))

p = [abs(n - X) for n in x]

print(reduce(gcd, p))

Submission status: Accepted

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

kyori=[]

for item in town:
    kyori.append(abs(item-start))
import fractions
temp=kyori[0]

for item in kyori:
    temp=fractions.gcd(item, temp)

print(temp)

Submission status: Accepted

Solution code:
from fractions import gcd

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

temp_list = [abs(num - x) for num in x_list]

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
distances = {}

for i in range(N):
    dist = A[i+1] - A[i]
    distances[dist] = None

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

distances = list(distances.keys())
gcd_calc = distances[0]

if N > 1:
    for dist in distances[1:]:
        gcd_calc = gcd(gcd_calc, dist)
        # if gcd_calc == 1:
        #     break

print(gcd_calc)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
distances = {}

for i in range(N):
    dist = A[i+1] - A[i]
    distances[dist] = None

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

distances = list(distances.keys())
gcd_calc = distances[0]

if N > 1:
    for dist in distances[1:]:
        gcd_calc = gcd(gcd_calc, dist)
        if gcd_calc == 1:
            break

print(gcd_calc)

Submission status: Accepted

Solution code:
from fractions import gcd

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

sub = []

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

max = sub[0]

for i in range(1,N):
    max = gcd(max, sub[i])

print(max)

Submission status: Accepted

Solution code:
import functools
import fractions
N,S = map(int,input().split())
x = list(map(int,input().split()))
D = [0]*N
D[0] = S-x[0]

for i in range(1,N):
  D[i] = x[i] - x[i-1]
ddd=functools.reduce(fractions.gcd, D)
if ddd < 0:
  ddd *= -1
print(ddd)

Submission status: Accepted

Solution code:

#ユークリッドの互除法( A < B　とし, O(logA))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

#3個以上の最大公約数を求める必要がある
# res=0 と初期化して、res=gcd(res,x[i])と更新する
# gcd(a,b,c,....) → gcd(gcd(gcd(a,b),c),...) 
res = 0
x = list(map(int,input().split()))

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

print(res)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

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

    ans = 0
    for x in X:
        ans = gcd(ans, abs(x - x0))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

_, X = map(int, input().split())
print(reduce(gcd, (abs(X - i) for i in map(int, input().split()))))

Submission status: Accepted

Solution code:
from fractions import gcd


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

Submission status: Accepted

Solution code:
import fractions

N, X = map(int, input().split(" "))
X = [X]
X.extend(map(int, input().split(" ")))
X.sort()
ans = X[1] - X[0]
for i in range(1, len(X) - 1):
    ans = fractions.gcd(ans, X[i + 1] - X[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions
from functools import reduce


def main():
    n, x = input_list()
    a = input_list()
    a.append(x)
    sa = list(sorted(a))
    kukan = []
    for i, v in enumerate(sa):
        if i+1 > len(sa)-1:
            break
        d = sa[i+1] - v
        kukan.append(d)
    print(gcd_list(kukan))


def input_list():
    return list(map(int, 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)

if __name__ == "__main__":
    main()

Submission status: Accepted

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