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: Time Limit Exceeded

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

y = [abs(xi - X) for xi in x]
k = min(y)

for i in range(k):
    p = k -i
    z = [yi % p for yi in y]
    if sum(z) == 0:
        print(p)
        break

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

while len(x)!=1:
    x = x[:-2] + [gcd(x[-2],x[-1])]

print(x[0])

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N, X = MI()
    L = LI()
    L = [abs(i-X) for i in L]
    ans = L[0]
    for i in L:
        ans = math.gcd(ans, i)
    print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

xdst = [x[i+1] - x[i] for i in range(N)]
#print(xdst)

ans = 10**10
if len(xdst) == 1:
    print(xdst[0])
    exit()

for i in range(N-1):
    ans = min(math.gcd(xdst[i], xdst[i+1]),ans)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
n, x = map(int, input().split())
ls = sorted(list(map(int, input().split())))
if x == 1:
    print(abs(x-ls[0]))
    exit()
distant = []
for i in range(n):
    diff = abs(ls[i]-x)
    distant.append(diff)
distant.sort()
a = distant[0]
for i in distant:
    g = gcd(a, i)
    a = g
print(g)

Submission status: Accepted

Solution code:
import sys,math
n,x=map(int,sys.stdin.readline().split())
xl=[*map(int,sys.stdin.readline().split())]
yl=[abs(x-i) for i in xl]


d=yl[0]
for i in range(n):
    d=math.gcd(d,yl[i])

print(d)

Submission status: Accepted

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

import math
ans = a[0]
for i in range(n-1):
    ans = math.gcd(ans,a[i+1])
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
def readinput():
    n,x=map(int,input().split())
    xx=list(map(int,input().split()))
    return n,x,xx

def main(n,x,xx):
    y=[0]*len(xx)
    for i in range(len(xx)):
        y[i] = abs(xx[i] - x)
    if len(y)==1:
        ans=y[0]
    else:
        ans=gcd(y[0],y[1])
        for i in range(2,n):
            ans=gcd(ans,y[i])
    return ans

if __name__=='__main__':
    n,x,xx=readinput()
    ans=main(n,x,xx)
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math

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

gcd = abs(X - A[0])
for a_i in A:
    gcd = math.gcd(gcd, abs(X-a_i))

print(gcd)

Submission status: Accepted

Solution code:
import math
n,x=map(int, input().split())
a=[int(x) for x in input().split()]

ans=abs(x-a[0])
for i in range(1,n):
    ans=math.gcd(abs(x-a[i]),ans)

print(ans)

Submission status: Accepted

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

xi.sort()
diff = []
for i in range(n):
    diff.append(abs(xi[i]-x))

import numpy
print(numpy.gcd.reduce(diff))

Submission status: Accepted

Solution code:
from math import gcd

n,x = map(int,input().split())
c = list(map(int,input().split()))
c.append(x)
c.sort()
arr = []
for i in range(n):
    arr.append(abs(c[i]-c[i+1]))
ans = arr[0]
if n>1:
    ans = gcd(arr[0],arr[1])
    for i in range(2,n):
        ans = gcd(ans,arr[i])
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd, numbers)
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(a[1])
c = sorted(b)
d = []
for i in range(a[0]):
  d.append(c[i+1]-c[i])
print(gcd(d))

Submission status: Accepted

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

ans=diff[0]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

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

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

dis = []

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

res = 0

for i in range(N):
   res = gcd(res, dis[i])

print(res)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque

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


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, X, x):
    x_abs = [abs(X - xi) for xi in x]
    ans = x_abs[0]
    for xi in x_abs[1:]:
        ans = gcd(ans, xi)
    print(ans)


if __name__ == '__main__':
    N, X = map(int, input().split())
    x = [int(i) for i in input().split()]
    solve(N, X, x)

    # # test
    # from random import randint
    # from func import random_str
    # N, X = 10 ** 5, randint(1, 10 ** 9)
    # x = [randint(1, 10 ** 9) for _ in range(N)]
    # solve(N, X, x)

Submission status: Accepted

Solution code:
import sys
import math
from functools import reduce

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

l=[]

for i in x:
        b=abs(i-k)
        l.append(b)

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

ans=(gcd_list(l))

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
xlist= list(map(int,input().split()))
if n == 1:
  print(abs(xlist[0]-x))
  exit()
ylist = []
for i in range(n):
  ylist.append(abs(xlist[i]-x))
from functools import reduce
from math import gcd
print(reduce(gcd,ylist))

Submission status: Accepted

Solution code:
import math

def gcd_list(nums):
  gcd = nums[0]
  for i in range(1,len(nums)):
    gcd = math.gcd(gcd,nums[i])
  return gcd

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

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

print(gcd_list(x))

Submission status: Accepted

Solution code:
def gcd(a, b):
    """最大公約数"""
    if b == 0: return a
    return gcd(b, a % b)
  

def mapt(fn, *args):
    return list(map(fn, *args))
 
 
def Input():
    return mapt(int, input().split(" "))
 
def main():
    N, X = Input()
    x = Input()
 
    if N == 1:
        print(abs(x[0] - X))
        exit()
 
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]
 
    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)
 
 
 
main()

Submission status: Accepted

Solution code:
import math

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

ans = []
for xx in X:
    ans.append(abs(x-xx))
    
a = ans[0]
for aa in ans:
    a = math.gcd(aa, a)
    
print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 01:58:46 2020

@author: liang
"""

from math import gcd

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

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

Submission status: Accepted

Solution code:
from math import gcd

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

aX = list(map(lambda x: abs(x-X), xs))

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,x = inpl()
a = inpl()
now = abs(a[0]-x)
for i in range(1,n):
    now = math.gcd(abs(a[i] - x),now)
print(now)

Submission status: Accepted

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

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

for i in range(1,n):
    tmp =  gcd(tmp,abs(l[i]-x))

print(tmp)

Submission status: Accepted

Solution code:
import fractions

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

l.append(x)
sl=sorted(l)

lis=[sl[i+1]-sl[i] for i in range(n)]

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce

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

    x.append(X)
    x = sorted(x)

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

    print(gcd(*d))


def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

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

now = a[0]
for i in a:
    now = gcd(now, i)

print(now)

Submission status: Accepted

Solution code:
import functools
import math

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

D = functools.reduce(lambda acc, x: math.gcd(acc, x), x_list, 0)

print(D)

Submission status: Accepted

Solution code:
import functools
import math

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

x_list.append(X)
num_list = sorted(x_list)
 
tmp = map(lambda x: abs(x[0] - x[1]),
          zip(num_list[:-1],num_list[1:]))

D = functools.reduce(lambda acc, x: math.gcd(acc, x), tmp, 0)

print(D)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

print(gcd(*a))

Submission status: Accepted

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

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

ans=0
for x in x_list:
  ans=gcd(ans, x)
print(abs(ans))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

print(reduce(math.gcd,[X[i+1]-X[i] for i in range(n)]))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, [abs(i-x) for i in c]))

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,X = mint()
x = lint()
x = [abs(i-X) for i in x]
D = x[0]
for i in x[1:]:
    D = gcd(D,i)
    if D==1:
        break
print(D)

Submission status: Accepted

Solution code:
import math
n,a=map(int,input().split())
x=list(map(int,input().split()))+[a]
x.sort()
if n==1:
  print(abs(x[0]-x[1]))
  exit()
res=x[1]-x[0]
for i in range(1,n):
  res=math.gcd(res,x[i+1]-x[i])
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


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

    if n == 1:
        minimum = abs(x_lst[0] - x)
    elif n == 2:
        minimum = abs(x_lst[1] - x_lst[0])
        lst = [abs(x_lst[1] - x), abs(x_lst[0] - x)]
        lst.sort()
        lst.reverse()
        for i in range(2):
            if minimum % lst[i] == 0:
                minimum = lst[i]
                break
    else:
        lst1 = []
        for i in range(n):
            if i != n - 1:
                lst1.append(abs(x_lst[i + 1] - x_lst[i]))

        minimum = math.gcd(lst1[0], lst1[1])
        for i in range(n - 1):
            if i != n - 2:
                minimum = min(minimum, math.gcd(lst1[i], lst1[i + 1]))

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

        lst2.sort()
        lst2.reverse()
        for i in range(n):
            if minimum % lst2[i] == 0:
                minimum = lst2[i]
                break

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a = sorted(a)
diff_list = [0] * n
for i in range(1, n + 1):
    diff_list[i - 1] = a[i] - a[i - 1]
g = diff_list[0]
import math
for i in range(1, n):
    g = math.gcd(g, diff_list[i])
print(g)

Submission status: Accepted

Solution code:
def resolve():
    from math import gcd
    _, X = [int(i) for i in input().split()]
    xx = [int(i) for i in input().split()]
    ans = abs(X - xx[0])
    for x in xx:
        ans = gcd(ans, abs(X - x))
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#再帰
def gcd(a, b):
	if b==0:
		return a
	return gcd(b, a%b)
#ループ
def gcd(a,b):
  while b:
    a,b = b,a%b
  return abs(a)

def solve(x_list):
	ans=0
	for x in x_list:
		ans=gcd(ans, x)
	return ans

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

print(solve(x_list))

Submission status: Accepted

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

    
ans=S[0]
for j in range(1,N):
    ans=math.gcd(ans,S[j])
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N,X = i_map()
    x = i_list()
    l = []
    for i in x:
        l.append(abs(X-i))
    ans = l[0]
    for k in l[1:]:
        ans = gcd(ans,k)
    print(ans)



if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from math import gcd 
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
if(N == 1): print(abs(x[0] - X))
else:
  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 math import *

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

Submission status: Accepted

Solution code:
from math import gcd

n, X = map(int, input().split())
xlst = list(map(int, input().split()))
ans = X - xlst[0]
for x in xlst:
    ans = gcd(ans, X - x)
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

dist = [0] * (N + 1)
for i in range(N):
  dist[i] += x_list[i+1] - x_list[i]
  
ans = gcd_list(dist)
print(ans)

Submission status: Accepted

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

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

a = reduce(gcd,li)
print(a)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

N, X = map(int, input().split())
if N>1: x = [int(_)-X for _ in input().split()]; print(gcd_list(x))
else: x = int(input()) - X; print(abs(x))

Submission status: Accepted

Solution code:

from math import gcd
from functools import reduce

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

res = reduce(gcd, [abs(v - X) for v in A])
print(res)

Submission status: Accepted

Solution code:
#36 C - Skip
import bisect
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x,reverse = False)

bisect.insort_left(x,X)
# 間隔の最小の素数
d_lis = []
for i in range(len(x)-1):
    d = x[i+1] - x[i]
    d_lis.append(d)
d_lis = sorted(d_lis,reverse = False)

ans = d_lis[0]
for j in range(1,len(d_lis)):
    ans = math.gcd(ans,d_lis[j])
print(ans)

Submission status: Accepted

Solution code:
import math

n, s = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in a:
    ans = math.gcd(ans, abs(i - s))
print(ans)

Submission status: Accepted

Solution code:
import math
n,x = map(int, input().split()) 
num_list = list(map(int, input().split())) 
res = 0
for i in num_list:
    res = math.gcd(res, abs(i-x))

print(res)

Submission status: Accepted

Solution code:
import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    if len(nums)==1:
        return nums[0]
    return functools.reduce(euclid, nums)



n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(k)
a.sort()

sa=[]

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



print(gcd(sa))

Submission status: Accepted

Solution code:
import math
from functools import reduce

def gcd(list):
  return reduce(math.gcd, list)

n, x = map(int, input().split())
a = map(lambda b: abs(int(b) - x), input().split())
print(gcd(a))

Submission status: Accepted

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

import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


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


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def main():
    n, x = input_int_list()
    X = input_int_list()
    ans = abs(x - X[0])
    for i in range(1, n):
        ans = gcd(ans, abs(x - X[i]))
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

res = 0
for i in xl:
    res = math.gcd(res, abs(i-x))

print(res)

Submission status: Accepted

Solution code:
import math
N,X= map(int,input().split())
x=list(map(int, input().split()))
x.append(X)
x.sort()
d=[]
if N==1:
  print(x[1]-x[0])
  exit()
for i in range(N):
  d.append(x[i+1]-x[i])
gc=math.gcd(d[0],d[1])
for i in range(N):
  gc=math.gcd(d[i],gc)
print(gc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x=map(int, input().split())
xlist=list(map(int, input().split()))
ylist=[]
for i in range(n):
  ylist.append(xlist[i]-x)
import math
ans=ylist[0]
for i in range(n):
  ans=math.gcd(ans,ylist[i])
print(ans)

Submission status: Accepted

Solution code:
import math
N,X = map(int,input().split())
xl = [abs(x-X)for x in map(int,input().split())]
ans = xl[0]

for x in xl[1:]:
    ans = math.gcd(ans,x)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

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

print(reduce(gcd, cnt))

Submission status: Accepted

Solution code:
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import math
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,X=map(int,pin().split())
  x=list(map(int,pin().split()))
  m=abs(x[0]-X)
  for i in range(1,N):
    m=math.gcd(abs(x[i]-X),m)
  print(m)
  return
main()

Submission status: Accepted

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

from functools import reduce

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

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

if N != 1:
    ret = []
    x.append(X)
    now = x[0]

    for i in x[1:]:
        ret += [i - now]
        now = i

    ret = sorted(ret)

    print(gcd_list(ret))

else:
    print(abs(x[0] - X))

Submission status: Accepted

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

x.append(X)
from math import gcd
g = x[1] - x[0]
for i in range(N):
    g = gcd(g, (x[i+1] - x[i]))

print(abs(g))

Submission status: Accepted

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
a = [int(s) for s in input().split()]
N = a[0]
st = a[1]
mini = int(-1)
b = [int(s) for s in input().split()]

for i in range(N):
    if abs(b[i] - st) < mini or mini == -1:
        mini = abs(b[i] - st)

yakulist = make_divisors(mini)
gyakulist = sorted(yakulist, reverse=True)
kazu = len(gyakulist)
flag = int(0)

for i in range(kazu):
    for j in range(N):
        if abs(b[j] - st) % gyakulist[i] != 0:
            flag = 1
        else:
            pass
    if flag == 0:
        print(gyakulist[i])
        break
    else:
        flag = 0

Submission status: Accepted

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

y = x[0]
for  i in range(1,N):
    z = x[i]
    y,z = max(y,z),min(y,z)
    while z!=0:
        y,z = z,y%z
print(y)

Submission status: Accepted

Solution code:
import fractions
def gcdlist(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    return ans

n,y=map(int,input().split())
x=list(map(int,input().split()))
x.append(y)
if y==1:
    print(abs(x[0]-1))
    exit()

l=[]
for i in range(n):
    l.append(abs(x[i+1]-x[i]))
print(gcdlist(l))

Submission status: Accepted

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

temp = abs(x- al[0])

for i in range(1,n):
    y = al[i]-al[i-1]
    temp = math.gcd(temp,y)
 
print(temp)

Submission status: Accepted

Solution code:
from math import gcd
n,start = map(int,input().split())
x_ls = list(map(int, input().split()))
diff_ls = [0] * n

for i in range(n):
    diff_ls[i] = abs(start-x_ls[i])

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

print(ans)

Submission status: Accepted

Solution code:
#https://note.nkmk.me/python-gcd-lcm/
import math
from functools import reduce

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

n,x = map(int,input().split())
a = list(map(int,input().split()))
tmp = []
for i in range(n):
    tmp.append(abs(a[i]-x))
    
print(gcd_list(tmp))

Submission status: Accepted

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

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

else:
  l=[]
  for i in range(N):
    l_=abs(X-x[i])
    l.append(l_)
  #print(l)
  ans=l[0]
  for i in range(1,len(l)):
    ans=gcd(ans,l[i])

  print(ans)

Submission status: Accepted

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

xx = list()
for i in range(N):
    xx.append(abs(X-x[i]))
num = xx[0]
for i in range(1,N):
    num = gcd(num,xx[i])
print(num)

Submission status: Accepted

Solution code:
import fractions

def main():
    N, start = map(int, input().split())
    X = list(map(int, input().split()))
    dists = []
    for x in X:
        dists.append(abs(x - start))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

# resの最大公約数を求める。　コードは reduce(gcd, list)
print(reduce(gcd, res))

Submission status: Accepted

Solution code:
from functools import reduce
import math

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

if len(a)==1:print(abs(a[0]));exit()
if len(a)==2:print(math.gcd(a[0],a[1]));exit()

l=[]
for y in range(n-1):
    l.append(a[y+1]-a[y])
    
print(reduce(lambda x,y:math.gcd(x,y),l))

Submission status: Accepted

Solution code:
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, x = read_ints()
    d = read_int_list()
    ans = abs(x - d[0])
    
    for i in range(1, n):
        ans = GCD(ans, abs(x - d[i]))
    print(ans)    

if __name__ == '__main__':
    Main()