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

Submission status: Accepted

Solution code:
import fractions

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os
# import math
import bisect
import collections
import itertools
from fractions import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X = il()
    T = il()
    T = sorted(T + [X])
    ret = abs(T[0] - T[1])
    for i in range(len(T)-1):
        ret = gcd(ret, abs(T[i]-T[i+1]))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
c = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
c.append(x)
c.sort()
g = c[1]-c[0]
for i in range(1,n):
    g = gcd(g,c[i+1]-c[i])
print(g)

Submission status: Accepted

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

distances = [abs(i - X) for i in target]

def GCD(x,y):
    if y == 0:
        return x
    else:
        return GCD(y, x % y)
res = 0
for d in distances:
    res = GCD(res, d)
print(res)

Submission status: Accepted

Solution code:
import numpy as np

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



n, X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x = np.array(x)
x = np.sort(x)
d = x[1:] - x[:-1]

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

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()))
Y=[abs(X[i]-x) for i in range(n)]
print(reduce(gcd,Y))

Submission status: Accepted

Solution code:
import fractions

n,x=list(map(int,input().split()))
X=list(map(int,input().split()))
X.append(x)
X=sorted(X)
Y=[X[i+1]-X[i] for i in range(n)]

if n==1:
  print(max(X)-min(X))
  
else:
  gcd=fractions.gcd(Y[0],Y[1])
  for i in range(2,n):
    gcd=fractions.gcd(gcd,Y[i])
  print(gcd)

Submission status: Accepted

Solution code:
import fractions


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

A.append(X)
A.sort()

diff = []
for a,b in zip(A, A[1:]):
    diff.append(b-a)

ans = diff[0]
for i in range(1,len(diff)):
    ans = fractions.gcd(ans, diff[i])


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

N, X = map(int, input().split())
a = reduce(gcd, map(lambda x: abs(int(x) - X), input().split()))

print(a)

Submission status: Accepted

Solution code:
from functools import reduce


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


n, X = map(int, input().split())
A = list(map(lambda x: abs(int(x)-X), input().split()))
print(reduce(gcd, A))

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
x = list(map(lambda x:abs(int(x)-X), input().split()))
def gcd_base(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def gcd(num_list):
    ans = 0
    for i in num_list:
        ans = gcd_base(ans, i)
    return ans

print(gcd(x))

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
pl=sorted(list(map(int,input().split()))+[x])
ans=abs(pl[1]-pl[0])
if len(pl)>1:
    for i in range(len(pl)-2):
        ans=fractions.gcd(ans,abs(pl[i+2]-pl[i+1]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
n, X = map(int, input().split())
x = sorted([int(i) for i in input().split()] + [X])
diff_x = [x[i + 1] - x[i] for i in range(n)]
if len(diff_x) == 1:
    print(diff_x[0])
else:
    d = gcd(diff_x[0], diff_x[1])
    for i in range(2, n):
        d = gcd(d, diff_x[i])
    print(d)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_c

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

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

ans = abs(x - nums[0])
for num in nums:
    d = abs(x - num)
    ans = gcd(d, ans)
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
l_n = list(map(int,input().split()))
l_n.append(M)
l_n.sort()
l_a = []
l_s = []
for i in range(N):
    l_a.append(l_n[i+1]-l_n[i])
min_number = l_a[0]
n_list = []
for i in range(1,int(min_number**0.5)+1):
    if min_number % i == 0:
        if i == min_number // i:
            pass
        else:
            n_list.append(min_number // i)
        n_list.append(i)
n_list.sort(reverse=True)
for i in n_list:
    if [j for j in l_a if j % i != 0] == []:
        print(i)
        exit()

Submission status: Accepted

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


def solve(N: int, X: int, x: "List[int]"):
    from fractions import gcd
    from functools import reduce
    return reduce(gcd, [abs(xx-X) for xx in x])


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, X, x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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


def solve(N: int, X: int, x: "List[int]"):
    from fractions import gcd
    from functools import reduce
    Y = sorted(x+[X])
    Z = [x2-x1 for x1, x2 in zip(Y, Y[1:])]
    return reduce(gcd, Z)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, X, x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

ans = abs(x[0]-X)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce
import sys
try:
    from typing import List
except ImportError:
    pass


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


def solve(N: int, X: int, x: "List[int]"):
    x2 = [abs(xi - X) for xi in x]
    print(reduce(gcd, x2))


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


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


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


N, X = map(int, input().split())
x = list(map(int, input().split()))
dif = [abs(X - x[0])]

if N > 1:
    for i in range(N - 1):
        dif.append(x[i + 1] - x[i])
print(abs(gcd_list(dif)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from functools import reduce
from fractions import gcd
#from math import gcd

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

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

print(reduce(gcd, x))

Submission status: Accepted

Solution code:
import fractions
def main():
    N, St = map(int, input().split())
    X = [int(a) for a in input().split()]
    X.append(St)
    X.sort()

    D = list()
    for i in range(len(X)-1):
      d = X[i+1] - X[i]
      D.append(d)
    ans = D[0]

    for i in range(1, len(D)):
        ans = fractions.gcd(ans, D[i])
    
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

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

print(gcd_list(sa_list))

Submission status: Accepted

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

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

for i in range(N):
  city[i] -= X
  city[i] = abs(city[i])

#print(city)

ans = city[0]

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

def myAnswer(N:int,X:int,x:list) -> int:
   ans = []
   for a in x:
      ans.append(abs(a-X))
   return gcd_list(ans)

def modelAnswer():
   return
def main():
   N,X = map(int,input().split())
   x = list(map(int,input().split()))
   print(myAnswer(N,X,x[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
import functools
import fractions

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

a.append(x)
a.sort()

for i in range(len(a)):
  a[i] = abs(a[i] - x)

gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True

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


def gcd_n(a, n):
    ans = a[0]
    for i in range(1, n):
        ans = gcd(ans, a[i])
    return ans


def main():
    N, X = MI()
    x = LI()
    x.append(X)
    x.sort()
    d = []

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

    print(gcd_n(d, len(d)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

from fractions import gcd
# slist = "abcdefghijklmnopqrstuvwxyz"
N,X = map(int,input().split())
arrA = list(map(int,input().split()))
arrA = abs(np.array(arrA) - X)
arrA = list(arrA)

while len(arrA)>1:
    a = arrA.pop()
    b = arrA.pop()
    c = gcd(a,b)
    arrA.append(c)

ans = arrA[0]
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
  if x[i]>X:
    x[i]=x[i]-X
  elif x[i]<X:
    x[i]=X-x[i]
  else:
    del x[i]
n=gcd_list(x)
print(n)

Submission status: Accepted

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

def hoge():
    global n,x,X
    ret=abs(X-x[0])
    for i in range(1,n):
        ret=gcd(abs(X-x[i]),ret)
    return ret

print(hoge())

Submission status: Accepted

Solution code:
import fractions

def gcd_list(a):
    ans = a[0]
    for i in range(1, N):
        ans = fractions.gcd(ans, a[i])
    return ans

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

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

print(gcd_list(dl))

Submission status: Accepted

Solution code:
import fractions

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

minimum = x[0]
for i in range(len(x)):
    x[i] = x[i] - X
    minimum = min(x[i], minimum)
# print(x, minimum)

gcd_value = fractions.gcd(x[0], x[0])
for i in range(len(x)):
    gcd_value = abs(fractions.gcd(gcd_value, x[i]))
    # print(gcd)
print(gcd_value)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
d = 0
for i in range(n):
    d = gcd(d, abs(xlis[i]-x))
print(d)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
if n > 1:
    d = gcd(abs(xlis[0]-x), abs(xlis[1]-x))
    for i in range(2, n):
        d = gcd(d, abs(xlis[i]-x))
    print(d)
else:
    print(abs(xlis[0] - x))

Submission status: Accepted

Solution code:
import fractions
n,x = map(int,input().split())
s = set(map(int,input().split()))
s.add(x)
l = list(s)
l.sort()
for i in range(len(l)-1):
  if i == 0:
    y = l[1]-l[0]
  else:
    y = fractions.gcd(l[i+1]-l[i],y)
print(y)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()
x = LIST()

if N == 1:
	print(abs(x[0] - X))
	exit()

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


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

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

x_list.sort()

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


print(gcd_list(tmp))

Submission status: Accepted

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

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

print(reduce(lambda a,b:fractions.gcd(a,b),list1,list1[0]))

Submission status: Accepted

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

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

answer = 0
for x in A:
  answer = gcd(answer, x)
print(answer)

Submission status: Accepted

Solution code:
def gcd(a, b):
    big = max(a, b)
    small = min(a, b)
    if small == 0:
        return big
    
    r = small
    while r != 0:
        r = big % small
        big = small
        small = r
        
    return big
   
N, X, *x = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
def ABC162C(a,b):#ユークリッドの互除法
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)

n,*x=map(int,open(0).read().split())
p=abs(x[-1]-x[-2])
for i in range(n):
    p=ABC162C(abs(x[i]-x[i+1]),p)
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,X = readInts()
    a = list(map(lambda x:abs(X-int(x)), input().split()))
    res = 0
    # 0で初期化していいのか
    from fractions import gcd
    for i in range(n):
        res = gcd(res,a[i])
    print(res)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import fractions

n,x=map(int,input().split())
X=list(map(int,input().split()))
A=[]
for i in range(n):
    if X[i]!=x:
        A.append(abs(X[i]-x))
g=A[0]
for i in range(n):
    g=fractions.gcd(g,A[i])
print(g)

Submission status: Accepted

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

ls_x = [abs(l - X) for l in ls]

import fractions

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

if N == 1:
    ans = abs(X-next(x))
else:
    ans = gcd(abs(X-next(x)), abs(X-next(x)))
    for i in x:
        ans = gcd(ans, abs(X-i))
print(ans)

Submission status: Accepted

Solution code:
def main():
    import fractions
    n,x=map(int, input().split())
    xn=list(map(int, input().split()))
    xn.append(x)
    xn.sort()
    for i in range(n):
        buf=xn[i+1]-xn[i]
        if i==0:
            d=buf
        else:
            d=fractions.gcd(d,buf)
    print(d)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# solution
# solution

import fractions
import math
import io

nim, mike = map(int, input().split())
are1 = list(map(int, input().split()))
are2, result = [abs(x - mike) for x in are1], 0

for i in are2:
    result = fractions.gcd(result, i)
print(result)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
N, X = map(int, input().split())
x = list(map(int, input().split()))
tmp = abs(x[0] - X)
for i in range(1,N):
  tmp = fractions.gcd(tmp,abs(x[i]-X)) # Xとの差分に対し、最大公約数を求める
print(tmp)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from fractions import gcd

def main():
    N, X = map(int, readline().rstrip().split())
    x = list(map(int, readline().rstrip().split()))
    x = [abs(e-X) for e in x]
    
    if N == 1:
        print(x[0])
        return
    
    g = gcd(x[0], x[1])
    if N == 2:
        print(g)
        return

    for e in x[2:]:
        g = gcd(g, e)
    
    print(g)  


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
def main():
    n, X = map(int,input().split())
    x = list(map(int,input().split()))
    sub = []
    min_s = 0
    for i, xx in enumerate(x):
        sub.append(abs(xx-X))

    min_s = min(sub)
    ans = 1
    flg = True
    s = list(set(sub))
    if X == 1:
        print(sub[0])
        return
    ans = s[0]
    for i, ss in enumerate(s):
        if i == 0:
            continue
        ans = fractions.gcd(ans,ss)

    print(ans)



if __name__ =='__main__':
    main()

Submission status: Accepted

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

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

import fractions
#最大公約数
ans = a[0]
for i in range(1, N):
    ans = fractions.gcd(ans, a[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(10 ** 6)


def input(): return sys.stdin.readline().rstrip()

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

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

ls = []

for i in range(n):
    ls.append(abs(x - x_list[i]))

ret = ls[0]

for i in range(1, n):
    ret = gcd(ret, ls[i])

print(ret)

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

nx = list(map(lambda a: abs(a - X),x))
g = reduce(gcd,nx)

print(g)

Submission status: Accepted

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

#109_c
import numpy as np
import math
from functools import reduce
from fractions import gcd

#最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

x.append(X)
sort_x = np.array(sorted(x))

kaisa = np.diff(sort_x, n=1).tolist()

print(gcd_list(kaisa))

Submission status: Accepted

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

def GCD(A):
    if len(A) == 1:
        return A[0]
    elif len(A) == 2:
        g = gcd(A[0],A[1])
    else:
        g = gcd(A[0],A[1])
        for i in range(2,len(A)):
            g = gcd(g,A[i])
    return g

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

x.sort()
for i in reversed(range(N+1)):
    x[i] -= x[0]

ans = GCD(x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n,x0=map(int,input().split())
d=list(map(lambda a:abs(int(a)-x0),input().split()))
ans=d[0] if len(d)==1 else fractions.gcd(d[0],d[1])
i=1
while i < n-1 and ans !=1:
    ans=min(ans,fractions.gcd(d[i],d[i+1]))
    i+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

X.append(K)
diff = []
for i,x in enumerate(X):
    if i != 0:
        diff.append(abs(X[i-1] - x))

print(gcd_list(diff))

Submission status: Accepted

Solution code:
from fractions import gcd
from bisect import insort

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


X.sort()
insort(X, x)
diff = []
for a,b in zip(X, X[1:]):
    diff.append(b - a)

ans = diff[0]
for num in diff[1:]:
    ans = gcd(ans, num)

print(ans)

Submission status: Accepted

Solution code:
import sys
import fractions
def input(): return sys.stdin.readline().rstrip()
import math

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

Submission status: Accepted

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

x.append(y)
x.sort()
d = []
for i in range(n):
    d.append(x[i+1]-x[i])
if len(d) !=1:
    ans = fractions.gcd(d[0],d[1])
    for i in range(n-1):
        ans = fractions.gcd(ans,d[i])
    print(ans)
else:
    ans = d[0]
    print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

dX = [abs(X - x) for x in X_list]
if len(dX) == 1:
    print(dX[0])
    exit(0)

D = [abs(X_list[i] - X_list[i + 1]) for i in range(0, N - 1)]
res = D[0]
for x in D[1:]:
    res = gcd(res, x)

ans = 0
for d in dX:
    ans = max(gcd(res, d), ans)
print(ans)