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

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

N, K = map( int, input().split())
X = list( map( int, input().split()))
now = abs( K - X[0])
for x in X:
    now = gcd(now, abs(x-K))
print(now)

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

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

for i in range(n):
    if i==0:
        tmp = dx[0]
    else:
        tmp = gcd(tmp, dx[i])
print(tmp)

Solution (Python):
from functools import reduce
def gcd(a,b):
  while b>0:
    a,b=b,a%b
  return a

n,x=map(int,input().split())
*l,=map(int,input().split())
*y,=map(lambda a:abs(a-x),l)
print(reduce(gcd,y))

Solution (Python):
from functools import reduce

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

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

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

print(gcd_list(x))

Solution (Python):
import fractions
n,x = map(int, input().split())
lis = [int(i) for i in input().split()]
lis2 = []
for nums in lis:
  lis2.append(abs(nums-x))
ans = 10000000000000
if n == 1:
  g = lis2[0]
else:
  i = 2
  g = fractions.gcd(lis2[0],lis2[1])
  while i < n:
    g = fractions.gcd(g,lis2[i])
    i += 1
print(g)

Solution (Python):
import sys
from collections import deque
import copy


from math import *


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

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, X] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    x_list = [X]
    for i in range(N):
        x = int(input_raw[i])
        x_list.append(x)
    x_list.sort()
    D = x_list[1] - x_list[0]
    for i in range(1, len(x_list)):
        D = gcd(D, x_list[i] - x_list[i - 1])
    print D

if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

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

vs = [abs(int(y) - x) for y in input().split()]

g = 0
for v in vs:
  g = gcd(g, v)

print(g)

Solution (Python):



import fractions
import functools


def gcds(xs):
    return functools.reduce(fractions.gcd, xs)


def max_d(x, ys):
    return abs(gcds(y - x for y in ys))


def main():
    n, x = (int(z) for z in input().split())
    ys = [int(z) for z in input().split()]
    print(max_d(x, ys))


if __name__ == '__main__':
    main()

Solution (Python):
def GCD(a,b): 
  if a<b:
    a,b = b,a

  r = a % b
  
  while r!=0:
    a = b
    b = r
    r = a % b
 
  return b

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

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

ans = T[0]
for i in range(1,N):
  ans = GCD(ans, T[i])
  
print(ans)

Solution (Python):

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
ass = values[0]
for i in range(n):
    ass = gcd(ass,values[i])
print(ass)

Solution (Python):
from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

dis = [0]*N
for i in range(N):
    dis[i] = x[i+1] - x[i]

print(gcdlist(dis))

Solution (Python):

from bisect import bisect_left
from fractions import gcd
def inpl(): return list(map(int, input().split()))

N, S = inpl()

X = [abs(x - S) for x in inpl()]
if N == 1:
    print(X[0])
else:
    ans = gcd(X[0], X[1])
    for x in X[1:]:
        ans = gcd(ans, x)
    print(ans)

Solution (Python):



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


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

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

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

x.append(X)
y=sorted(x)
z=[]
for i in range(N):
    z.append(y[i+1]-y[i])
Min=z[0]
for i in range(N-1):
    if Min>gcd(z[i],z[i+1]):
        Min=gcd(z[i],z[i+1])
print(Min)

Solution (Python):



import array
from bisect import *
from collections import *
from functools import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys




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

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)

Solution (Python):
def nl(): return list(map(int, input().split()))
def gcd(x, y):
    if x < y:
        
        x, y = y, x
    while True:
        r = x % y
        if r == 0:
            break
        else:
            x, y = y, r
    return y

N, X = nl()
x = nl()
x2 = list(map(abs, (map(lambda v: v - X, x))))

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

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

Solution (Python):
from fractions import gcd

N,X = map(int, raw_input().split())
x = map(int, raw_input().split())
ans = abs(x[0]-X)
for t in x:
  ans = gcd(ans, abs(t-X))
print ans

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,x]=i2()
y=i2()
y.append(x)
y.sort()
def gcd(a,b):
  while b:
    if a<b:
        c=b
        b=a
        a=c
    if b:a%=b
  return a
z=y[1]-y[0]
for i in range(1,n):
 z=gcd(y[i+1]-y[i],z)
print(z)

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


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


rec = sorted(rec)
gc =  rec[0]
for i in range(1, n):
    gc = gcd(rec[i], gc)

print(gc)

Solution (Python):
N,X = map(int,input().split(" "))
x = list(map(int,input().split(" ")))
x = list(map(lambda y: abs(y - X),x))



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

if N == 1:
    print(x[0])
    exit(0)
ans = gcd(x[0],x[1])
if N == 2:
    print(ans)
    exit(0)
for i in range(2,N):
    ans = gcd(ans,x[i])

print(ans)

Solution (Python):
from fractions import gcd

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

a = x[0]
for xi in x[1:]:
    a = gcd(a, xi)
print(a)

Solution (Python):
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = [int(xi) for xi in input().split()]
x.append(X)
x = sorted(x)
diffs = [x[i+1] - x[i] for i in range(N)]
if len(diffs) == 1:
    print(diffs[0])
else:
    print(reduce(gcd, diffs))

Solution (Python):
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from functools import reduce


def findGCD(a:int, b:int) -> int:
    
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a

n,x = li()
a = li()

a_diff = [abs(ai - x) for ai in a]
ans = reduce(findGCD, a_diff)

print(ans)

Solution (Python):



II = lambda: int(input())
MI = lambda: map(int, input().split())


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

def main():
    N, X = MI()
    xs = []
    for x in MI():
        x -= X
        if x != 0:
            xs.append(abs(x))
    a = xs[0]
    for x in xs:
        a = gcd(a, x)
    return a


if __name__ == "__main__":
    print(main())

Solution (Python):
n,c=map(int,input().split())
x=list(map(int,input().split()))
x=[x[i]-c for i in range(n)]
ans=x[0]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for t in x:
    ans=gcd(ans,t)
print(abs(ans))

Solution (Python):


from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

def GCD(a, b):
    num1 = max(a, b)
    num2 = min(a, b)
    rem = 1
    while rem > 0:
        rem = num1 % num2
        num1 = num2
        num2 = rem
    return num1

N, X = map(int, raw_input().split())
x_ = map(int, raw_input().split())
x = [abs(num - X) for num in x_]

ans = x[0]
for num in x:
    ans = GCD(ans, num)

print ans

Solution (Python):
from functools import reduce

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

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

print(reduce(gcd,d))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,X = inpl()
xx = inpl()
xx.append(X)
xx.sort()

dists = set()
for i in range(N):
	dists.add(xx[i+1]-xx[i])

dists = list(dists)
dists.sort()

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

ans = dists[0]
for d in dists:
	ans = gcd(ans,d)

print(ans)

Solution (Python):
N, X = [int(_) for _ in input().split()]
xs = [int(_) for _ in input().split()]

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

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

result = xs[0]

for x in xs[1:]:
    result = gcd(result, x)

print(result)

Solution (Python):

from fractions import gcd
n,x = map(int, input().split())
ary = [abs(x-int(i)) for i in input().split()]

d = ary[0]
for i in ary[1:]:
    d = gcd(i,d)

print(d)

Solution (Python):
import fractions

N,X = map(int,input().split())
src = list(map(int,input().split()))
ans = abs(X - src[0])
for a,b in zip(src,src[1:]):
    ans = fractions.gcd(ans, abs(b-a))
print(ans)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from fractions import gcd

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, X = reads()
xs = reads()
ans = abs(reduce(lambda x, y: gcd(x, y), [y-X for y in xs], 0))
print(ans)

Solution (Python):
def gcd(a,b):
    x=max([a,b])
    y=min([a,b])
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
y=[abs(x[i]-X) for i in range(N)]
if N==1:
    print(y[0])
    exit()
ans=gcd(y[0],y[1])
for i in range(2,N):
    ans=gcd(ans,y[i])
print(ans)

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

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

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


def main():
    n,x = LI()
    a = LI()
    t = [abs(c-x) for c in a if x != c]
    g = min(t)
    for c in t:
        g = fractions.gcd(c,g)

    return g


print(main())

Solution (Python):
def  gcd(a,b):
    return a if b==0 else gcd(b,a%b)
n,x = map(int,raw_input().split())
ret = 0
for v in map(int,raw_input().split()):
    ret = gcd(ret, abs(x-v))
print ret

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


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


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


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


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result




dp = None


def main():
    N, X = li_input()
    C = li_input()
    D = []

    for c in C:
        D.append(abs(X - c))

    print(gcd_list(D))



main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n,x = na()
a = na()

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

g = 0
for v in a:
    g = gcd(g, abs(v-x))
print(g)

Solution (Python):
N, X = map(int, input().split())
A = list(map(int, input().split()))
diff = [abs(a - X) for a in A]


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


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

print(diff[0])