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:
def gcd(a, b):
  if(b % a == 0):
    return a
  else:
    ans = 1
    i = 2
    while a!= 1:
      if(a % i == 0):
        while a % i == 0:
          a/= i
        while b % i == 0:
          b/= i
          ans*= i
        i+= 1
    return ans
          

def ggcd(lista):
  l = lista[0]
  for i in range(1, len(lista)):
    l = gcd(l, lista[i])
  return l

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

for item in x:
  d.append(abs(X- item))
  
print(ggcd(d))

Submission status: Time Limit Exceeded

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

for item in x:
  d.append(abs(X- item))

m = min(d)
ans = 0
flag = 0

for i in range(m, 1, -1):
  flag = 1
  for j in range(N):
    if(d[j] % i != 0):
      flag = 0
      break
  if(flag == 1):
    ans = i
    break
  
if(flag == 0):
  print(1)
  
else:
  print(ans)

Submission status: Time Limit Exceeded

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

for item in x:
  d.append(abs(X- item))

m = min(d)
ans = 0

for i in range(m, 0, -1):
  flag = 1
  for j in range(N):
    if(d[j] % i != 0):
      flag = 0
      break
  if(flag == 1):
    ans = i
    break
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import numpy as np

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

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


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


if n > 1:
    ans = euclid(x[0], x[1])


    for xi in x[2:]:
        ans = euclid(ans, xi)
        if ans == 1:
            break

else:
    ans = x[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import numpy as np

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

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


def gcd(nums):
    return functools.reduce(euclid, nums)


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


print(gcd(x))

Submission status: Time Limit Exceeded

Solution code:
import functools
import numpy as np

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

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


def gcd(nums):
    return functools.reduce(euclid, nums)


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


print(gcd(x))

Submission status: Time Limit Exceeded

Solution code:
import math
n,x = map(int,input().split())
X = list(map(int,input().split()))
X = list(map(lambda a:abs(a-x),X))

def hcf(*x):                                #计算最大公约数
    smaller=min(x)
    for i in reversed(range(1,smaller+1)):
        if list(filter(lambda j: j%i!=0,x)) == []:
            return i
print(hcf(*X))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,x=map(int,input().split())
    X=[int(_) for _ in input().split()]
    X.append(x)
    X.sort()
    XX=[0]*n
    for i in range(n):
        XX[i]=X[i+1]-X[i]
    ans=min(XX)
    while True:
        flag=True
        for xx in XX:
            if xx%ans!=0:
                flag=False
        if flag==False:
            ans-=1
        else:
            break
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def func(a):
  global mx
  mx = min(mx, abs(int(a)-x))
  return int(a)

n,x = map(int,input().split())
mx = 10**9
xlist = list(map(func,input().split()))

for i in range(mx,0,-1):
  for j in range(n):
    if abs(x-xlist[j])%i != 0:
      break
  else:
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
data=input().rstrip().split()
n=int(data[0])
x=int(data[1])

roc = input().rstrip().split()
roc=[abs(int(i)-x) for i in roc]
ans=0
a=min(roc)
while ans!=len(roc):
  ans=0
  for j in roc:
    if j%a==0:
      ans+=1
    else:
      continue
  a-=1
print(a+1)

Submission status: Time Limit Exceeded

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

x_min = min(x)

for i in range(x_min, 0, -1):
    cnt = 0
    for j in x:
        if j % i != 0:
            break
        else:
            cnt += 1
    if cnt == N:
        print(i)
        exit()

Submission status: Time Limit Exceeded

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

x_min = min(x)

for i in range(x_min, 0, -1):
    if all([_ % i == 0 for _ in x]):
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import sys
n, x = map(int, input().split())
points = [int(e) for e in input().split()]
points.sort(reverse=True)
min_difference = float('inf')
difference_list = []
for i in range(len(points)-1):
    difference_list.append(points[i] - points[i+1])
difference_list.append(abs(points[-1] - x))
min_difference = min(difference_list)
difference = 0
for i in range(min_difference):
    difference = min_difference - i
    for ind, j in enumerate(set(difference_list)):
        if (j % difference) == 0:
            if ind == len(set(difference_list))-1:
                print(difference)
                sys.exit()
        else:
            break

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt, floor
from functools import reduce


def divisors(a):
    return {i for i in range(1, floor(sqrt(a)) + 1) if a % i == 0}\
        .union({a // i for i in range(1, floor(sqrt(a)) + 1) if a % i == 0})


def greatest_common_divisor(a, b):
    return max(divisors(a).intersection(divisors(b)))


def greatest_common_divisor_of(lst):
    return reduce(greatest_common_divisor, lst)


X = int(input().split()[1])
xi = list(map(int, input().split()))
x = [abs(x - X) for x in xi]
print(greatest_common_divisor_of(x))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

x += [x_ini]

# print(x)

x2 = [x[i] - min(x) for i in range(n + 1)]

# print(x2)

x_ini -= min(x)

# print(x_ini)

ans = reduce(gcd, x2)

print(ans)

Submission status: Time Limit Exceeded

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

res = []

s = 10**10

for i in range(n):
    s = abs(li[i] - x)
    res.append(s)
    
s = min(res)
    
while True:
    for i in range(n):
        if res[i]%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

Submission status: Time Limit Exceeded

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

s = 10**10

for i in range(n):
    s = min(s, abs(li[i] - x))
    
while True:
    for i in range(n):
        if abs(li[i]-x)%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

Submission status: Time Limit Exceeded

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

l=y[0]
for i in range(l):
    k=True
    for j in range(n):
        if y[j]%(l-i)!=0:
            k=False
            break
    if k:
        print(l-i)
        break

Submission status: Time Limit Exceeded

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

def True_array(s,k):
    for i in s:
        if i%k!=0:
            return False
    return True

l=y[0]
for i in range(l):
    if True_array(y,l-i):
        print(l-i)
        break

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
r=list(map(int,input().split()))
r.append(x)
r.sort()
d=[]
e=[]
for i in range(n):
  if r[i+1]!=r[i]:
    d.append(r[i+1]-r[i])
d=list(set(d))
#print(d)
while len(d)>1:
  m=min(d)
  for i in range(len(d)-1):
    if d[i+1]!=d[i]:
      e.append(d[i+1]-d[i])
  d=e[:]
  d.append(m)
  d=list(set(d))
  d.sort()
  #print(d)
print(*d)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import fractions
import sys
sys.setrecursionlimit(10**6) 

n,x = [int(x) for x in stdin.readline().rstrip().split()]

li = list(map(int,stdin.readline().rstrip().split()))

def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
lin = []
for i in range(len(li)):
    lin.append(abs(li[i]-x))
gcd = gcd_all(lin)
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
N, X = map(int, input().split())
city = list(map(int, input().split()))
a = []

for i in range(N):
	a.append(abs(city[i] - X))
	a = sorted(a, reverse = True)
	
s = a.pop(0)

while a:
	s = gcd(s, a.pop(0))
	if s == 1:
		break
print(s)

Submission status: Time Limit Exceeded

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

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

for i in range(N):
	a.append(abs(city[i] - X))
	a = sorted(a, reverse = True)
	
s = a.pop(0)

while a:
	s = gcd(s, a.pop(0))
	if s == 1:
		break
print(s)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(x)
b=[]
m=10**9

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
if n==1:
  print(abs(x-a[0]))
else:
  for i in range(n):
    for j in range(i+1,n+1):
      b.append(abs(a[i]-a[j]))
  for i in range(len(b)-1):
    for j in range(i+1,len(b)):
      m=min(m,gcd(b[i],b[j]))
  print(m)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x=list(map(lambda t:t-min(x),x))
def gcd(a,b):
    while b:
        a,b=b,a%b
    return(a)
a=10**10
for i,j in zip(x,x[1:]):
    a=min(a,gcd(i,j))
print(a)

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    divisors = []
    n=abs(n)
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return set(divisors)

def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  s=make_divisors(x[0]-m)
  for i in range(1,n):
    s=s&make_divisors(x[i]-x[i-1])
  print(max(s))
  
main()

Submission status: Time Limit Exceeded

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

n, start = [int(a) for a in input().split()]
x = [int(b) for b in input().split()]
x = x + [start]
x = [c - min(x) for c in x]
DifferenceList = list()
for i, v in enumerate(x):
    if (i > 0):
        DifferenceList.append(abs(x[i] - x[i - 1]))

g = DifferenceList[0]
for d in DifferenceList:
    g = gcd(g, d)

print (g)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
for i in lst:
    ans.append(abs(i-X))
small = min(ans)
for i in ans:
    if i%small == 0:
        continue
    else:
        while i != small:
            i = i%small
            small = small - i
print(small)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
for i in lst:
    ans.append(abs(i-X))
small = min(ans)
for i in ans:
    if i%small == 0:
        continue
    else:
        while i != small:
            i = i - small
            if i < small:
                small = small - i
print(small)

Submission status: Time Limit Exceeded

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

cityList = [abs(X-int(i)) for i in input().split()]
flag = True

max_D = min(cityList)

while max_D > 1:
    for city in cityList:
        if city % max_D != 0:
            flag = False
            max_D -= 1
            break
        flag = True
        
    if flag:        
        break
print(max_D)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
li = list(map(int, input().split()))
t = []
for i in li:
    t.append(abs(i - x))
for j in range(min(t)):
    if all(k % (min(t) - j) == 0 for k in t):
        print(min(t) - j)
        exit()

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
b=[]
for i in input().split():
  b.append(abs(int(i)-a[1]))
def ucl(a,b):
  if a%b==0:
    return b
  else:
    return ucl(b,a%b)
while len(b)>1:
  b.append(ucl(b[0],b[1]))
  del b[0],b[1]
print(b[0])

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
b=[]
for i in input().split():
  b.append(abs(int(i)-a[1]))
def ucl(a,b):
  if a%b==0:
    return b
  else:
    return ucl(b,a%b)
while len(b)>1:
  b.append(ucl(b[0],b[1]))
  del b[0]
  del b[0]
print(b[0])

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
b=list(map(lambda b:abs(int(b)-a[1]),input().split()))
def ucl(a,b):
  if a%b==0:
    return b
  else:
    return ucl(b,a%b)
while len(b)>1:
  b.append(ucl(b[0],b[1]))
  del b[0]
  del b[0]
print(b[0])

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
b=list(map(lambda b:abs(int(b)-a[1]),input().split()))
def ucl(a,b):
  if a%b==0:
    return b
  else:
    return ucl(b,a%b)
while len(b)>1:
  b+=[ucl(b[0],b[1])]
  del b[0]
  del b[0]
print(b[0])

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()

if N==1:
    print(max(dist))
else:
    m = min(dist)
    dist.remove(m)
    dist_2 = [int(i%m) for i in dist]
    dist_2.sort()
    while len(dist_2)>0 and dist_2[0]==0:
        dist_2.remove(0)
    dist_2.append(m)
    D = max(dist_2)
    for i in reversed(range(1, D+1)): #最大公約数を1から順に考える
        for j in range(len(dist_2)): #全ての数を割ってみる
            if dist_2[j]%i != 0:
                flag = False
                break
            else:
                flag = True
        if flag:
            D = i
            break
    print(D)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()

if N==1:
    print(max(dist))
else:
    m = min(dist)
    dist.remove(m)
    dist_2 = [int(i%m) for i in dist]
    dist_3 = [m]
    for l in range (len(dist_2)):
        if dist_2[l]!=0:
            dist_3.append(dist_2[l])
    D = max(dist_3)
    for i in reversed(range(1, D+1)): #最大公約数を1から順に考える
        for j in range(len(dist_3)): #全ての数を割ってみる
            if dist_3[j]%i != 0:
                flag = False
                break
            else:
                flag = True
        if flag:
            D = i
            break
    print(D)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()
D = 1

for i in reversed(range(1, min(dist)+1)): #最大公約数を1から順に考える
    for j in range(len(dist)): #全ての数を割ってみる
        if dist[j]%i != 0:
            flag = False
            break
        else:
            flag = True
    if flag:
        D = i
        break
print(D)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()
D = [1]

for i in range(1, min(dist)+1): #最大公約数を1から順に考える
    D.append(i)
    for j in range(len(dist)): #全ての数を割ってみる
        if dist[j]%i != 0 and D.count(i)>=1:
            D.remove(i)
print(max(D))

Submission status: Time Limit Exceeded

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

import fractions

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

d = []
for i in a:
    d.append(abs(i-x))
m = 10**9
for i in d:
    for j in d:
        m = min(m, fractions.gcd(i,j))
print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, x = map(int, input().split())
ans = 1
def check(n, li):
    for i in li:
        if i != 0:
            if abs(i) % n != 0:
                return False
    return True
li = list(map(int, input().split()))
li.append(x)
li = list(set(li))
li.sort()
start_index = li.index(x)
li = np.array(li)
if start_index == len(li)-1:
    n = li[start_index] - li[start_index - 1]
    for i in reversed(range(1, n+1)):
        if check(i, li-x) and i > ans:
            ans = i
            break
        
elif start_index == 0:
    n = li[start_index+1] - li[start_index]
    for i in reversed(range(1, n+1)):
        if check(i, li-x) and i > ans:
            ans = i
            break
else:
    n = li[start_index] - li[start_index - 1]
    for i in reversed(range(1, n+1)):
        if check(i, li-x) and i > ans:
            ans = i
            break
    n = li[start_index+1] - li[start_index]

    for i in reversed(range(1, n+1)):
        if check(i, li-x) and i > ans:
            ans = i
            break
        if ans > i:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions


def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	a=[abs(i-j) for i in x_list for j in x_list if i!=j]
	print(functools.reduce(fractions.gcd,a))

resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

from fractions import gcd

x=[abs(x[i+1]-x[i]) for i in range(N)]

def gcd_many(_list):
    if len(_list)==1:
        return abs(_list[0])
    elif len(_list)==2:
        return gcd(_list[0],_list[1])
    else:
        return gcd(_list[0],gcd_many(_list[1:]))
        
print(abs(gcd_many(x)))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import time
import re
import math

def main():
    n,start=map(int,input().split())
    X=list(map(int,input().split()))
    mx=0
    dmx=0
    for a in X:
        dmx=max([dmx,abs(start-a)])
    for D in range(1,dmx+1):
        f=1
        for a in range(n):
            if (X[a]-start)%D!=0:
                f=0
        if f==1:
            mx=max([mx,D])
    print(mx)
main()

Submission status: Time Limit Exceeded

Solution code:
n,X=map(int,input().split())
x=sorted(list(map(int,input().split())))
#print(x)
XX=[X for _ in range(n)]
#print(XX)
a=[]
k=2
t=1
for i in range(n):
    a.append(abs(x[i]-XX[i]))
ans=[max(a)]
#print(ans)
for j in range(n):
    if(x[j]>X):
        while(X!=x[j]):
            if(j>0):
                t=(x[j]-x[j-1])//ans[0]
            #print(t)
            b=X+(ans[0]*t)
            #print(ans)
            #print(b)
            if(b!=x[j]):
                if(ans[-1]//k==0):
                    break
                ans.append(ans[-1]//k)
                ans=sorted(ans)
                k+=1
            else:
                X=X+ans[0]*t
    else:
        if(j>=0):
            t=(X-x[j])//ans[0]
            #print(t)
        while(X!=x[j]):
            if(j>=0):
                t=(X-x[j])//ans[0]
            #print(t)
            else:
                continue
            b=X-ans[0]*t
            if(b!=x[j]):
                ans.append(ans[-1]//k)
                ans=sorted(ans)
                #print(ans)
                k+=1
            else:
                X=X-ans[0]*t
#print(ans)
print(ans[0])

Submission status: Time Limit Exceeded

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

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

def multigcd(List):
    for _ in range(len(List)-1):
        List=[gcd(List[0],List[1])]+List[2:]
    return List

print (multigcd(Lxabs)[0])

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

x2 = map(lambda y: y-min(x), x)

print(reduce(gcd,x2))

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
m=10**10
for i in a:
    dis=abs(i-x)
    if m>dis:
        m=dis
while True:
    j=1
    for i in a:
        num=abs(i-x)
        if num%m!=0:
            j=0
    if j:
        break
    else:
        m-=1
print(m)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
huga=list(map(int,input().split()))
hoge=[]
for i in range(n):
  hoge.append(abs(huga[i]-x))
hoge.sort(reverse=True)
D=hoge[0]

for i in range(D):
  ans=D-i
  flag=0
  for j in range(n):
    if(hoge[j]%ans>0):
      flag=1
  if(flag==0):
    print(ans)
    break

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a

    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = [x[0]]
for i in range(len(x)):
    for j in range(i+1, len(x)):
        l.append(gcd(max(x[i], x[j]), min(x[i], x[j])))
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a

    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = [x[0]]
for i in range(len(x)):
    for j in range(1, len(x)):
        l.append(gcd(max(x[i], x[j]), min(x[i], x[j])))
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
# from math import gcd

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

def main():
    ds = list(map(lambda n: abs(X - n), P))
    # ans = reduce(lambda a, b: gcd(a, b), ds)
    d = min(ds)
    while d > 0:
        if all(map(lambda distance: distance % d == 0, ds)) == True:
            break
        d = d - 1
    ans = d
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

min_distance = min(positions_from_X)

n = min_distance

for d in sorted([i for i in range(1,n+1) if n%i==0], reverse=True):
    flg = d
    for p in positions_from_X:
        if p%d !=0:
            flg=0
            break
    if flg:
        break

print(flg)

Submission status: Time Limit Exceeded

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y:
        while x%y:
            z = x%y
            x, y = y, x
        else:
            return z
    else:
        return y


x.append(X)
x.sort()
# print(x)
# d = []
# for i in range(N):
#     d.append(x[i+1]-x[i])
# print(d)
for i in range(N):
    if i == 0:
        c = x[i+1]-x[i]
    else:
        c = gcd(x[i+1]-x[i], c)
print(c)

Submission status: Time Limit Exceeded

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y:
        while x%y:
            z = x%y
            x, y = y, x
        else:
            return z
    else:
        return y


x.append(X)
x.sort()
# print(x)
d = []
for i in range(N):
    d.append(x[i+1]-x[i])
# print(d)
for i in range(N):
    if i == 0:
        c = d[i]
    else:
        c = gcd(d[i], c)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    if all([x % min(x_ls) == 0 for x in x_ls]):
        break
    else:
        x_ls = [x % min(x_ls) for x in x_ls]
    x_ls = [x for x in x_ls if x != 0]
print(min(x_ls))

Submission status: Time Limit Exceeded

Solution code:
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**10
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)


N, X = LI()
X_list = LI()
#  if N == 1:
#      print(abs(X_list[0] - 1))
#      exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

results = []
for i in range(1, result+1):
    if all(x % i == 0 for x in X_diff):
        results.append(i)

print(results[-1])

Submission status: Time Limit Exceeded

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

y = [abs(X-i) for i in x]
D = min(y)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
L = list(map(int, input().split()))
L.append(X)
L.sort()
cand = []
def gcd(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small + 1):
        if ((x % i == 0) and (y % i == 0)):
            gcd = i
    return gcd

for i in range(N):
    cand.append(abs(L[i] - L[i+1]))

for i, can in enumerate(cand):
    if i == 0:
        tmp = can
        continue
    tmp = gcd(tmp, can)
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
values = raw_input()
n,x = int(values.split(" ")[0]), int(values.split(" ")[1])
cities = raw_input()
cities = [int(i) for i in cities.split(" ")]

distances = []
for i in cities:
	distances.append(abs(i-x))
m = max(distances)

D = m
while(D<=m):
	pos = x
	flag = True
	for i in range(len(cities)):
		if cities[i]<pos:
			k = (cities[i]-pos)/float(-D)
		else:
			k = (cities[i]-pos)/float(D)
		if k!=int(k):
			flag = False
		pos = cities[i]
		#print("\t",k, pos)

	if flag == True:
		print(D)
		break
	D -= 1

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  min_C = min(C)
  ans = 1
  for i in range(min_C, 1, -1):
    if all([c % i == 0 for c in C]):
      ans = i
      break
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
for i in range(n[0]-1):
    X[0]=gcd(X[0],X[1])
    X=[X[0]]+X[2:]
print(max(X))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

X.append(x)

X.sort()

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

for j in range(max(dif),0,-1):
    if all(x%j==0  for x  in dif):
        print(j)
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**8)

from fractions import gcd

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

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

# def gcd(m,n):
#     mx = max(m,n)
#     mn = min(m,n)
#     tmp = mx%mn
#     if tmp == 0:
#         return mn
#     else:
#         return gcd(mn, tmp)

def gcd_list(data):
    if len(data)==1:
        return data[0]
    tmp = gcd(data[0], data[1])
    if len(data)==2:
        return tmp
    else:
        new_data = [tmp]+data[2:]
        return gcd_list(new_data)

# print(gcd_list([2,4,8]))
print(gcd_list(X))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**8)

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

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

def gcd(m,n):
    mx = max(m,n)
    mn = min(m,n)
    tmp = mx%mn
    if tmp == 0:
        return mn
    else:
        return gcd(mn, tmp)

def gcd_list(data):
    if len(data)==1:
        return data[0]
    tmp = gcd(data[0], data[1])
    if len(data)==2:
        return tmp
    else:
        new_data = [tmp]+data[2:]
        return gcd_list(new_data)

# print(gcd_list([2,4,8]))
print(gcd_list(X))

Submission status: Time Limit Exceeded

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

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

x.sort()
#x.reverse()

xmin = x[0]
#xmin = x[N-1]
'''
div = []
for i in range(int(xmin/2)+1, 0, -1):
	if xmin % i == 0:
		div.append(i)

for d in div:
	for xi in x:
		if xi % d != 0:
			break
	else:
		D = d
		break

print(D)
'''
for d in range(xmin,0,-1):
	for xi in x:
		if xi % d != 0:
			break
	else:
		D = d
		break

print(D)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
n = max(max(x),X)//N 
x.append(X)
for i in range(n,0,-1):
    xmod = list(map(lambda y:y % i,x))
    if xmod.count(xmod[0]) == len(xmod):
        print(i)
        break