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 fractions

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

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

diff = [-1 for i in range(N)]
for i in range(N):
    diff[i] = abs(x[i] - X)

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

Submission status: Accepted

Solution code:
from fractions import gcd
n, s = map(int, raw_input().split())
xs = [ int(i) for i in raw_input().split()]
diff = [ abs(x-s) for x in xs]
print(reduce(gcd, diff))

Submission status: Accepted

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

firstline=input("")
N,X=firstline.split()
N=int(N)
X=int(X)
secondline=input("")
xi=secondline.split()
dis = list(map(lambda x: abs(int(x)-X), xi))
result = dis[0]
for i in dis[1:]:
    result = gcd(result, i)

print(result)

Submission status: Accepted

Solution code:
def gcd(a, b):

	while b:

		a, b = b, a % b

	return a

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n,x0 = map(int, input().split())
xs = map(int, input().split())
ys = [abs(x-x0) for x in xs]


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

for i,y in enumerate(ys):
  if i==0:
    y0 = y
  else:
    y0 = gcd(y,y0)
print(y0)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def convert(i):
	return int(i) - x

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

n, x = map(int, input().split())
# h1 = int(input())
# n = int(input())
cities = map(convert, input().split())

def main():
	print(abs(my_gcd(cities)))
			
main()

Submission status: Accepted

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

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

x.append(X)
x.sort()

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

Submission status: Accepted

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

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

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

xx_new = [abs(i-X) for i in xx]
xx_new.sort()

pair = 0

for i in xx_new:
  if pair ==0:
    pair = i
  else:
    pair = gcd(i,pair)
    
print(pair)

Submission status: Accepted

Solution code:
import math
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a


a,b = [int(i) for i in input().split(' ')]
xs = [int(i) for i in input().split(' ')]
#a = pow(10, 5)

temp = 0
result = 0
for i, x in enumerate(xs):
    if i == 0:
        result = abs(x - b)
    else:
        result = gcd(abs(x - temp), result)
    temp = x
print(result)

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
import sys

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

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

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



x.append(X)
x.sort()

ANS=gcd(x[1]-x[0],x[2]-x[1])

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

print(ANS)

Submission status: Accepted

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

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

x = list(map(int, input().split()))
ans = float("inf")
for i in range(0,n):
    x[i] = abs(x[i]-X)
    if i >= 1:
        x[i] = gcd(x[i],x[i-1])
    ans = min(ans,x[i])
print(ans)

Submission status: Accepted

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


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

    A = sorted(A)

    if N == 1:
        print(A[1] - A[0])
        exit()

    g = 1
    g = gcd(A[1] - A[0], A[2] - A[1])
    for i in range(1, len(A)):
        g = gcd(g, A[i] - A[i - 1])
            
    print(g)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
xs = [_ - xs[0] for _ in xs]
diffs = [xs[i]-xs[i-1] for i in range(1, len(xs))]
def gcd(a, b):
    if(a<b): return gcd(b, a)
    if a % b == 0:
      return b
    else:
      r = a % b
      return gcd(b, r)

prev = diffs[0]
for cur in diffs[1:]:
    prev = gcd(prev, cur)
print(prev)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

ans = gcd_list([abs(c - X) for c in cities])

print(ans)

Submission status: Accepted

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


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

y = [abs(xi - X) for xi in x]
r = y[0]

for i in range(N-1):
    if y[i+1] != 0:
        r = gcd(r, y[i+1])

print(r)

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

arr = list(map(int,input().split()))
arr.sort()

minn =0;
temp =0;

if n > 1:

	flag=0;
	
	for i in range(n):

		if i < n-1:
			temp = arr[i+1]-arr[i];
			minn = gcd(temp,minn);

	if minn==0:

		print( abs(x-arr[0]));

	for i in range(n):

		if x == arr[i]:
			flag=1;
			break;
		else:

			diff = abs(x-arr[i])
			if minn !=0 and diff%minn==0:
				flag=1;
				break;
	if flag==1:
		print(minn)
	else:

		maxx = 0;

		for i in range(n):

			diff = abs(x-arr[i]);
			temp = gcd(minn,diff);

			if temp > maxx:
				maxx = temp;
		print (maxx);
else:

	print (abs(x-arr[0]));

Submission status: Accepted

Solution code:
from fractions import gcd


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

x.append(X)
x.sort()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gratest_common_factor(x,y):
    while y:
        amari = x % y

        x = y
        y = amari
    return x


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

l2 = list(map(lambda t: t-x, l))

for i in range(n-1):
    l2[1] = gratest_common_factor(l2[0],l2[1])
    del l2[0]

print(abs(l2[0]))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(gcd, dx)

print(mdx)

Submission status: Accepted

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

d = [0 for _ in range(n)]
for i in range(n):
    d[i] = abs(x[i] - X)

d = sorted(list(set(d)))

if n == 1:
    print(d[0])
    exit()

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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

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

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

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

print(D)

Submission status: Accepted

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

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

xs[0] -= X
g = xs[0]
import math
for i in range(1,N):
    xs[i] -= X
    g = gcd(g,xs[i])
print(abs(g))

Submission status: Accepted

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


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

x_sorted = sorted(x_list)

x_gaps = [x_sorted[i+1] - x_sorted[i] for i in range(0, n-1)]

if len(x_gaps) == 0:
    print(abs(x_sorted[0]))
elif len(x_gaps) == 1:
    print(gcd(abs(x_list[0]), abs(x_list[1])))
else:
    result = x_sorted[0]
    for i in range(0, n-2):
        if i == 0:
            result = gcd(x_gaps[0], x_gaps[1])
        else:
            result = gcd(result, x_gaps[i+1])
    print(result)

Submission status: Accepted

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

x.append(X)
x.sort()
diff = list(set([i-j for i, j in zip(x[1:], x[:-1])]))

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

comm = diff[0]
for i in diff:
  while i > 0:
    comm, i = i, comm%i

print(comm)

Submission status: Accepted

Solution code:
inputs = raw_input().replace("\n", "").split(" ")
N, X = map(int, inputs)
inputs = raw_input().replace("\n", "").split(" ")
#xs = map(int, inputs)
xs = [abs(int(input_) - X) for input_ in inputs]

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

if N >= 2:
    for i in xrange(1, N):
        if i >= 2:
            y = gcd(y, xs[i])
        else: 
            y = gcd(xs[0], xs[1])
else:
    y = xs[0]

print y

Submission status: Accepted

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


# 最小公倍数
def gcd(a, b):
        while b:
                a, b = b, a % b
        return a

# 最大公約数
def lcm(a, b):
        return a * b // gcd (a, b)


ans = 0
for i, x in enumerate(x_list):

    diff = abs(x - X)

    # print(i, x, diff, ans)

    if i == 0:
        ans = diff
    else:
        larger = min(ans, diff)
        smaller = max(ans, diff)

        if smaller % larger == 0:
            ans = larger
        else:
            ans = gcd(ans, diff)

print(ans)

Submission status: Accepted

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


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

xs.append(X)
xs.sort()

D = [xs[i + 1] - xs[i] for i in range(N)]

res = min(D)
for d in D:
    if res == 1:
        break
    
    if d % res == 0:
        continue

    res = lcm(d, res)
    
print(res)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs = sorted(xs)
m = 999999999999999999
diffs = []
for idx,e in enumerate(xs):
  if idx==0:
    continue
  diff = abs(e - xs[idx-1])
  diffs.append(diff)
diffs = sorted(diffs)
for idx,dif in enumerate(diffs):
  if idx == 0:
    continue
  if gcd(diffs[idx], diffs[idx-1]) < m:
    m = gcd(diffs[idx], diffs[idx-1])
if len(diffs) == 1:
  m = diffs[0]
print(m)

Submission status: Accepted

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

def minus_x(t):
    return abs(int(t) - x)
cities = sorted(list(map(minus_x,input().split(" "))))

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

if n == 1:
    ans = cities[0]
else:
    ans = gcd(cities[0],cities[1])
    for i in range(2,n-1):
        ans = gcd(cities[i],ans)

print(ans)

Submission status: Accepted

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

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


for i in range(N):
  D.append(abs(A[i]-X))

ans=min(D)
for i in range(len(D)):
  ans=gcd(ans,D[i])
  
print(ans)

Submission status: Accepted

Solution code:

#import functools
#import math

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

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

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

a = []

for i in range(n):
    tmp = abs(w[i]-x)
    a.append(tmp)
    
ans = a[0]

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

#print(functools.reduce(math.gcd, a))

Submission status: Accepted

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines() # no strip

#from math import gcd
from fractions import gcd


def main():
    n, xx = na()
    xs = na()
    xs = [abs(x - xx) for x in xs]

    if len(xs) == 1:
        print(xs[0])
        return
    
    m = float('inf')
    v = xs[0]
    for x in xs[1:]:
        m = min(m, gcd(x, v))

    print(m)

main()

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
  
def gcd_list(y):
    if len(y)==1:
        return y[0]
    if len(y)==2:
        return gcd(y[0],y[1])
    else:
        return gcd(gcd_list(y[:len(y)/2]),gcd_list(y[len(y)/2:]))

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

x = map(int,raw_input().split())

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

print gcd_list(x)

Submission status: Accepted

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

x = sorted(x+[X])
x_diff = [x[i+1]-x[i] for i in range(n)]
# print(x, x_diff)
ans = x_diff[0]
for i in range(1, n):
    ans = fractions.gcd(ans, x_diff[i])
print(ans)

Submission status: Accepted

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

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

def maximum_d(cities, x):
    distances = set()
    for city in cities:
        distances.add(abs(x - city))
    if 0 in distances:
        distances.remove(0)

    result = None
    for distance in distances:
        if result:
            result = gcd(result, distance)
        else:
            result = distance
    return result

def main():
    n, x = [int(s) for s in input().split()]
    cities = [int(s) for s in input().split()]

    print(maximum_d(cities, x))

main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
ip = input().split()
st = int(ip[1])
 
li = []
 
ip2 = input().split()
for i in ip2:
    li.append(abs(int(i) - st))
 
print(gcd_list(li))

Submission status: Accepted

Solution code:
import fractions

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

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

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

distance=[0]*N

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

distance.sort()

D=distance[0]
for i in range(N):
  D=min(D,fractions.gcd(D,distance[i]))
print(D)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(gcd_multi(*dif_list))

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
ans = abs(X-x[0])
now = X
for i in x:
    if abs(now - i) % ans:
        ans = gcd(ans, abs(now-i))
    now = i

print(ans)

Submission status: Accepted

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

if N==1:
	print abs(A[0]-X)
	quit()

for i,x in enumerate(A):
	t=abs(x-X)
	if i==0:  D=t
	else:
		D=fractions.gcd(D,t)

print D

Submission status: Accepted

Solution code:
N, S = map(int, input().split())
x = list(map(int, input().split()))
x.append(S)
x.sort()
diff = []
for i in range(N):
    diff.append(x[i + 1] - x[i])

# 最小公倍数を求める
def lcm(a, b):
    while b != 0:
        a, b = b, a % b
    return a

ans = diff[0]
for d in diff[1:]:
    ans = lcm(ans, d)
print(ans)

Submission status: Accepted

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


def euclid(a,b):
    big = max(a,b)
    small = min(a,b)
    
    r = big % small
    while(r != 0):
        big = small
        small = r
        r = big % small

    return small

#first
haba = x[0] - X

for i in range(1,N):
    haba = euclid(haba,x[i]-X)
    if haba == 1:
        break

print(abs(haba))

Submission status: Accepted

Solution code:
from functools import reduce

n, x = [int(y) for y in input().split()]
xs = [int(y) for y in input().split()]

xs = {abs(y-x) for y in xs}

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

print(reduce(gcd, xs))

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
xs = [abs(int(k)-x) for k in input().split()]
xs.sort()
d = xs[0]
for x in xs:
    y =d
    while y!=0:
        x,y = y,x%y        
    d=x
print(d)

Submission status: Accepted

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

def devidable(numbers,i):
    for number in numbers:
        if number%i: return False
    return True

def gcd(numbers):
    i=min(numbers)
    while True:
        if devidable(numbers,i): return i
        else: i-=1

x.append(X)
x.sort()
y=[]

for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
    
print(gcd(y))

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


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


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

    a.append(x)
    a.sort()

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

    print(g)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y != 0:
        temp = y
        y = x % y
        x = temp
    return x


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

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

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

ans = dist_list[0]
for e in dist_list:
    ans = gcd(ans, e)


print(ans)

Submission status: Accepted

Solution code:
def gr(x,y):
    while y:
        amari = x % y
        x = y
        y = amari
    return x
n,x = map(int,input().split())
lis = list(map(int,input().split()))
li = []
for i in range(n):
  if abs(lis[i]-x) != 0:
    li.append(abs(lis[i]-x))
li.sort()
if len(li) == 1:
  print(abs(li[0]))
  exit()
ans = abs(li[0]-li[1])

for i in range(len(li)-1):
  ans = gr(ans,abs(li[i+1]))
print(ans)

Submission status: Accepted

Solution code:
n, x0 = [int(_) for _ in input().split(' ')]
x = [abs(int(_) - x0) for _ in input().split(' ')]

def gcm(p, q):
    if p % q == 0:
        return abs(q)
    else:
        return gcm(q, p % q)

if n == 1:
    print(x[0])
else:
    answer = x[0]
    for i in range(n - 1):
        answer = gcm(answer, x[i + 1])
    print(answer)

Submission status: Accepted

Solution code:
import fractions
import functools

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

ans = functools.reduce(fractions.gcd, map(lambda y: abs(y - x), xs))
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
n, k = map(int, input().split())
distlist = [abs(a-k) for a in list(map(int, input().split()))]

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

max_d = gcd_list(distlist)
print(max_d)

Submission status: Accepted

Solution code:
'''input
2 1
555 556
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n+1):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc

Submission status: Accepted

Solution code:
def main():
    """
    1 <= N  <= 10^5
    1 <= X  <= 10^9
    1 <= xi <= 10^9
    xi != xj
    xi != X
    """
    N, X = map(int, input().split())
    *xs, = map(int, input().split())

    ans = f(N, X, xs)
    print(ans)


def f(N, X, xs):
    """
    直線上に N 個の都市
    i 番目の都市は座標 xi

    あなたの目的は、これら全ての都市を 1度以上訪れること
    あなたは、はじめに正整数 Dを設定
    その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行う

        移動 1: 座標 yから座標 y+Dに移動する
        移動 2: 座標 yから座標 y−Dに移動する

    全ての都市を 1 度以上訪れることのできる Dの最大値を求めよ
    ここで、都市を訪れるとは、その都市のある座標に移動すること


    D=1, OK
    """
    ds = [abs(X - x) for x in xs]
    ans = ds[0]
    from fractions import gcd

    for d in ds:
        ans = gcd(d, ans)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

b = []
for i in range(n):
    b.append(abs(a[i]-x))

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

if n == 1:
    print(b[0])
else:
    ans = gcd(b[0], b[1])
    for i in range(2, n):
        ans = gcd(ans, b[i])
    print(ans)

Submission status: Accepted

Solution code:
import fractions

n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))

ans = k - xs[0]

for x in xs:
    if k == x:
        continue
    ans = fractions.gcd(ans, abs(k - x))
    # print(ans)

print(ans)

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split()))
pos = list(map(int, input().split()))
dis = []

for p in pos:
	dis.append(abs(p - X))

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

dis.sort()
ans = dis[0]
for d in dis:
	ans = gcd(d, ans)
print(ans)

Submission status: Accepted

Solution code:
import functools
import fractions
N,X=map(int,input().split())
x=list(map(int,input().split()))
def minus(n):
  return n-X
x=list(map(minus, x)) 


gcd = functools.reduce(fractions.gcd, x)
print(abs(gcd))

Submission status: Accepted

Solution code:
import platform
ver = platform.python_version_tuple()
if int(ver[1]) < 5:
    from fractions import gcd
else:
    from math import gcd

from functools import reduce
from sys import stdin, stdout

input = lambda: stdin.readline()
# write = stdout.write

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

    city = [abs(i - X) for i in Xn]
    ans = reduce(gcd, city)
    print(ans)

main()

Submission status: Accepted

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

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

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

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


d = x[0]

for i in x:
	d = gcd(d,i)
print(d)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

import copy
import math
import fractions
from functools import reduce

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

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

def main(n, start, x):
    pos = copy.deepcopy(x)
    pos.append(start)
    sp = sorted(pos)
    # print(sorted_pos)
    sabun = [ (sp[i+1] - sp[i]) for i in range(n)]
    # print(sabun)
    print(gcd_list(sabun))
        
if __name__ == '__main__':
    try:
        n, start  = list(map(int, input().strip().split(' ')))
        x = list(map(int, input().strip().split(' ')))
        main(n, start, x)
    except EOFError:
        pass

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd_list(pos))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

N, X = [int(v) for v in input().split()]
x = [abs(int(v) - X) for v in input().split()]
x.sort()
d = gcd_list(x)
print(d)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

z = []
for i in y:
    z.append(abs(i-x))

print(gcd_list(z))

Submission status: Accepted

Solution code:
import fractions

n, x = map(int, input().split())
array = [int(x) for x in input().split()]
tmp = abs(array[0]-x)
for i in array:
    tmp = fractions.gcd(tmp, abs(i-x))
print(tmp)

Submission status: Accepted

Solution code:
from fractions import gcd


n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = abs(l[0]-x)

for m in l:
    ans = gcd(ans, abs(m-x))

print(ans)

Submission status: Accepted

Solution code:
# time complexity: O(NlogN)
# space complexity: O(N)

from fractions import gcd
from functools import reduce

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

N, X = [int(elem) for elem in input().split(' ')]
x_list = [int(elem) for elem in input().split(' ')]
assert len(x_list) == N

difference_list = [abs(X - x) for x in x_list if X - x != 0]
max_gcd = gcd_list(difference_list)
print(max_gcd)

Submission status: Accepted

Solution code:
from fractions import gcd
import functools

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

Submission status: Accepted

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

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N):
    t = gcd(t,x[k+1]-x[k])

print(t)

Submission status: Accepted

Solution code:
import fractions, math
n,x=map(int, input().split())
a=list(map(int, input().split()))
mina=min(a+[x])
a=[i-mina for i in a]+[x-mina]
f=max(a)
for i in a:
    if i!=0:
        f=fractions.gcd(f,i)
print(f)

Submission status: Accepted

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

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

ans = 0
for x in xs:
    d = abs(x - X)
    if ans == 0:
        ans = d
    else:
        ans = GCD(ans, d)

print(ans)

Submission status: Accepted

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

from collections import Counter

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

A0 = A[0]
ans = []
ans2 = []
for i in range(1,int(abs(A0)**.5)+1):
    if A0%i==0 and i not in ans:
        ans.append(i)

ans2 = ans.copy()
for a in ans:
    if abs(A0//a) not in ans:
        ans2.append(abs(A0//a))

Ans = 1
for a in ans2:
    for i in range(N):
        if A[i]%a==0:
            continue
        else:
            break
    else:
        Ans = max(Ans,a)

print(Ans)

Submission status: Accepted

Solution code:
def GCD(x,y):
    if x < 0:
        x = -x
    if y < 0:
        y = -y
    #x > yとなるようにする
    if x <= y:
        tmp = x
        x = y
        y = tmp
    r = x % y
    while r != 0:
        x = y
        y = r
        r = x % y
    return y
n,x = map(int,input().split())
xl = list(map(int,input().split()))
G = x-xl[0]
for i in range(n):
    G = GCD(G,x-xl[i])
print(G)

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())
xx = list(map(int,input().split()))
xx.append(x)
xx.sort()

dif=[]

for i in range(1,n+1):
    dif.append(xx[i]-xx[i-1])

print(gcd_list(dif))

Submission status: Accepted

Solution code:
import math  
  
# method to print the divisors 
def printDivisors(n,arr) : 
      
    # Note that this loop runs till square root 
    i = 1
    while i <= math.sqrt(n): 
          
        if (n % i == 0) : 
              
            # If divisors are equal, print only one 
            if (n // i == i) : 
                arr.append(i)
            else:
                arr.append(i)
                arr.append(n//i) 
        i = i + 1

n,k=map(int,input().split())
arr=list(map(int,input().split()))
for i in range(n):
    arr[i]=abs(arr[i]-k)
arrx=[]
printDivisors(min(arr),arrx)
arrx.sort(reverse=True)
for i in range(len(arrx)):
    flag=0
    for j in range(len(arr)):
        if(arr[j]%arrx[i]!=0):
            flag=1
            break
    if(flag==0):
        print(arrx[i])
        exit(0)

Submission status: Accepted

Solution code:
import sys

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

def abs(a):
    if a<0:
        return -a
    else:
        return a

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

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

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

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

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

print(abs(ans))

Submission status: Accepted

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


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

ret = a[0]

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def gcd_list(numbers):
    return reduce(gcd, numbers)
na = lambda: list(map(int, input().split()))
n, X = na()
x = na()
x.append(X)
x.sort()
l = []
for i in range(len(x)-1):
    l.append(x[i+1]-x[i])
print(gcd_list(l))

Submission status: Accepted

Solution code:
from fractions import gcd

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

A = sorted(list(map(int,input().split()))+[X])

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

G = B[0]
if G>1:
    for b in B[1:]:
        G = gcd(G,b)
        if G==1:break
            
print(G)