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:
S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
n = max(max(x),X)//N 

for i in range(n,0,-1):
    xmod = list()
    xmod.append(X % i)
    for y in range(0,N):
        xmod.append(x[y] % i)
    if xmod.count(xmod[0]) == len(xmod):
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x, ps):
    res = {}
    for prime in primes:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    y = do_prime_fact(x[1] - x[0], primes)
    ps = y.keys()
    ys = [do_prime_fact(x[i+1] - x[i], ps) for i in range(len(x)-1)]
    d = 1
    for k in ps:
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

Submission status: Time Limit Exceeded

Solution code:
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x):
    res = {}
    for prime in primes:
        if x == 1:
            return res
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
        primes.append(x)
    return res

def solve(x):
    ys = [do_prime_fact(x[i+1] - x[i]) for i in range(len(x)-1)]
    d = 1
    for k in ys[0].keys():
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

Submission status: Time Limit Exceeded

Solution code:
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x):
    res = {}
    for prime in primes:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    ys = [do_prime_fact(x[i+1] - x[i]) for i in range(len(x)-1)]
    d = 1
    for k in ys[0].keys():
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

Submission status: Time Limit Exceeded

Solution code:
def solve(X, xs):
    divs = range(1, int(10 ** 4.5) + 1)
    def divisors(X, smaller_only=False):
        fwd, bwd = [], []
        for p in divs:
            if X % p == 0:
                fwd.append(p)
                if not smaller_only and X // p != p:
                    bwd.append(X // p)
        bwd.reverse()
        return fwd + bwd

    s = None
    for x in xs:
        ds = set(divisors(abs(x - X)))
        if s:
            s &= ds
        else:
            s = ds
    return max(s)

def test():
    print(solve(1, [2 ** i for i in range(30)]))

if __name__=='__main__':
    N, X = map(int, input().split())
    xs = map(int, input().split())

    print(solve(X, xs))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factor1, factor2):
    counters = [Counter(factor1), Counter(factor2)]
    if len(factor1) > 0 and len(factor2) > 0:
        return list(reduce(lambda x, y: x & y, counters).elements())
    elif len(factor2) == 0:
        return factor1
    else:
        return factor2

factors = []
for l in loc:
    factors = find_shared_factors(prime_factors(abs(l-X)), factors)
for i in range(N):
    for j in range(N):
        if i < j:
            factors = find_shared_factors(prime_factors(abs(loc[i]-loc[j])), factors)

r = reduce(lambda x,y: x*y, factors) if len(factors) > 0 else abs(max(loc)-X)

print(r)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
D=0
for i in range(N-1):
    if Xi[i]==Xi[i+1]+1 or Xi[i+1]==Xi[i]+1:
        D=1
        break
if D==0:
    D=Xi[0]
    c=0
    a=0
    while c!=1:
        for i in range(N):
            a=0
            if (Xi[i]%D)!=0:
                a=1
                D-=1
                break
        if a==0:
            c=1
print(D)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
D=0
for i in range(N-1):
    if Xi[i]==Xi[i+1]+1 and Xi[i+1]==Xi[i]+1:
        D=1
        break
if D==0:
    D=Xi[0]
    c=0
    a=0
    while c!=1:
        for i in range(N):
            a=0
            if (Xi[i]%D)!=0:
                a=1
                D-=1
                break
        if a==0:
            c=1
print(D)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
D=Xi[0]
c=0
a=0
while c!=1:
    for i in range(N):
        a=0
        if (Xi[i]%D)!=0:
            a=1
            D-=1
            break
    if a==0:
        c=1
print(D)

Submission status: Time Limit Exceeded

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

diffx=[abs(X-x[i]) for i in range(N)]
minDiff=min(diffx)
isFinished=0
for i in range(minDiff,0,-1):
    if minDiff%i==0:
        canDivide=1
        for j in range(N):
            if diffx[j]%i:
                canDivide=0
                break
        if canDivide:
            print(i)
            isFinished=1
            break
    if isFinished:
        break

Submission status: Time Limit Exceeded

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

tmp=abs(X-min(x))
isFinished=0
for i in range(tmp,0,-1):
    if tmp%i==0:
        canDivide=1
        for j in range(N):
            tmp=abs(X-x[j])
            if tmp%i:
                canDivide=0
                break
        if canDivide:
            print(i)
            isFinished=1
            break
    if isFinished:
        break

Submission status: Time Limit Exceeded

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

tmp=abs(X-x[0])
flag=0
for i in range(tmp,0,-1):
    if tmp%i==0:
        canDivide=1
        for j in range(N):
            tmp=abs(X-x[j])
            if tmp%i:
                canDivide=0
                break
        if canDivide:
            print(i)
            flag=1
            break
    if flag:
        break

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
    B.append(abs(A[i] - X))
m = min(B)
#print(B)
#print(m)

#"""
#最大公約数を求める
while m >= 2:
    a = 0
    for value in B:
        #print(value,m)
        if value % m != 0:
            m -= 1
            a = 1
            break
    if a == 0:
        break

print(m)

Submission status: Time Limit Exceeded

Solution code:
def gcm(a,b):
    g = max(a,b)
    s = min(a,b)
    while g % s != 0:
        g = max(a,b)
        s = min(a,b)
        g = g % s
    return s

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

    for i in range(n):
        X[i] -= x
        if X[i] < 0:
            X[i] *= -1

    m = X[0]
    for c in X[1:]:
        m = gcm(c,m)

    print(m)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def gcm(a,b):
    g = max(a,b)
    s = min(a,b)
    while g % s != 0:
        g = g % s
    return s

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

    for i in range(n):
        X[i] -= x
        if X[i] < 0:
            X[i] *= -1

    m = X[0]
    for c in X[1:]:
        m = gcm(c,m)

    print(m)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

def LCM(m,n):
  for i in range(1,m+1)[::-1]:
    if n%i==0:
      return i
    
N,X=(int(i) for i in input().split(' '))
x=[int(i) for i in input().split(' ')]
x=[X]+x
x=quick_sort(x)
D=abs(x[1]-x[0])
for i in range(N):
  D=LCM(D,abs(x[i+1]-x[i]))
print(D)

Submission status: Time Limit Exceeded

Solution code:
def LCM(m,n):
  for i in range(1,m+1)[::-1]:
    if n%i==0:
      return i
    
N,X=(int(i) for i in input().split(' '))
x=[int(i) for i in input().split(' ')]
x=[X]+x
D=abs(x[1]-x[0])
for i in range(N):
  D=LCM(D,abs(x[i+1]-x[i]))
print(D)

Submission status: Time Limit Exceeded

Solution code:
def LCM(m,n):
  for i in range(1,m+1)[::-1]:
    if n%i==0:
      return i
    
N,X=(int(i) for i in input().split(' '))
x=[int(i) for i in input().split(' ')]
x=[X]+x
x.sort()
D=x[1]-x[0]
for i in range(N):
  D=LCM(D,x[i+1]-x[i])
print(D)

Submission status: Time Limit Exceeded

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

def gcd(li):
    li.sort()
    for i in range(1,li[0]+1):
        for ii in li:
            if ii%i != 0:
                break
        else:
            gdc = i
    return(gdc)

x_list.append(X)
x_list.sort()

x_len = list()
for i in range(1,N+1):
    x_len.append(x_list[i]-x_list[i-1])

print(gcd(x_len))

Submission status: Time Limit Exceeded

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

def gcd(int_list):
    int_list.sort(reverse = True)
    for i in range(1,int_list[0]+1):
        for ii in int_list:
            if ii%i != 0:
                break
        else:
            gdc = i
    return(gdc)

x_list.append(X)
x_list.sort()

x_len = list()
for i in range(1,N+1):
    x_len.append(x_list[i]-x_list[i-1])

print(gcd(x_len))

Submission status: Time Limit Exceeded

Solution code:
# Skip
n, large_x = map(int, input().split())
x = (list(map(int, input().split())))
x.append(large_x)
x = sorted(x, reverse=True)
ran_ = []
for i in range(len(x)-1):
    ran_.append(x[i] - x[i+1])
ran = max(ran_)
flag = True
for r in reversed(range(ran+1)):
    flag = True
    for p in range(len(x)-1):
        if x[p] % r != x[p+1] % r:
            flag = False
            break
    if flag:
        print(r)
        exit()

Submission status: Time Limit Exceeded

Solution code:
# Skip
n, large_x = map(int, input().split())
x = (list(map(int, input().split())))
x.append(large_x)
x = sorted(x, reverse=True)
ran = x[0] - x[1]
flag = True
for r in reversed(range(ran+1)):
    flag = True
    for p in range(len(x)-1):
        if x[p] % r != x[p+1] % r:
            flag = False
            break
    if flag:
        print(r)
        exit()
print('None')

Submission status: Time Limit Exceeded

Solution code:
# import math


def make_divisor_list(num):
    if num <= 0:
        # return []
        return make_divisor_list(-num)
    elif num == 1:
        return [1]
    else:
        divisor_list = [1]
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
        return divisor_list


# print(make_divisor_list(24))

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

# print(xlist)

shiftedX = [x - X for x in xlist]

# print(shiftedX)

divisor_set_list = [set(make_divisor_list(x)) for x in shiftedX]
# print(divisor_set_list)

div_set = divisor_set_list[0]

for s in divisor_set_list:
    div_set = div_set & s

# print(div_set)

print(max(div_set))

Submission status: Time Limit Exceeded

Solution code:
#abc110 C
N, X = map(int, input().split())
x = list(map(int, input().split()))
distance = [ abs(x[i]-X) for i in range(N)]


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
flag=0
n,X=map(int,input().split())
x=list(map(int,input().split()))
x=np.array(x)
for d in range(int(min(abs(x-X))),0,-1):
  flag=0
  for i in x:
    if int(abs(X-i))%d!=0:
      flag=1
      break
  if flag==0:
    print(d)
    break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
flag=0
n,X=map(int,input().split())
x=list(map(int,input().split()))
x=np.array(x)
for d in range(min(abs(x-X)),0,-1):
  flag=0
  for i in x:
    if abs(X-i)%d!=0:
      flag=1
      break
  if flag==0:
    print(d)
    break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
flag=0
n,X=map(int,input().split())
x=list(map(int,input().split()))
x=np.array(x)
for d in range(min(abs(x-X)),0,-1):
  flag=0
  for i in x:
    if (X-i)%d!=0:
      flag=1
      break
  if flag==0:
    print(d)
    break

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

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

d_kouho_max = max(dist_list)

for d in reversed(range(d_kouho_max)):
    able = True
    for dist in dist_list:
        if dist%(d+1) == 0:
            pass
        else:
            able = False
            break
    if(able):
        d_max = d+1
        break

print(d_max)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

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

dist_list = list()

for x in xn:
    dist_list.append(abs(y-x))

d_kouho_max = max(dist_list)

for d in reversed(range(d_kouho_max)):
    able = True
    for dist in dist_list:
        if dist%(d+1) == 0:
            pass
        else:
            able = False
            break
    if(able):
        d_max = d+1
        break

print(d_max)

Submission status: Time Limit Exceeded

Solution code:
c, d = (int(i) for i in input().split())  
a = [int(i) for i in input().split()]
b = a.copy()
 
k = 0
for i in a:
    b[k] = abs(i - d)
    k += 1
 
m = min(b) 
 
def dec():
 
    i = m
    while i > 0:
        if m% i == 0: 
            k = 0
            for j in b:
                if j%i ==0:
                    k +=1
                if k==c:
                    return i
            if i == m:
                i -= i//2
        else:
            i -=1            
print(dec())

Submission status: Time Limit Exceeded

Solution code:
c, d = (int(i) for i in input().split())  
a = [int(i) for i in input().split()]
b = a.copy()
 
k = 0
for i in a:
    b[k] = abs(i - d)
    k += 1
 
m = min(b) 
 
def dec():
 
    i = m
    while i > 0:
        if m% i == 0: 
            k = 0
            for j in b:
                if j%i ==0:
                    k +=1
                if k==d:
                    return i
            i -= i//2
        else:
            i -=1
 
 
 
 
                
print(dec())

Submission status: Time Limit Exceeded

Solution code:



c, d = (int(i) for i in input().split())  
a = [int(i) for i in input().split()]
b = a.copy()

k = 0
for i in a:
    b[k] = abs(i - d)
    k += 1

m = min(b) 

def dec():

    i = m
    while i > 0:
        if m% i == 0: 
            k = 0
            for j in b:
                if j%i ==0:
                    k +=1
                if k==len(b):
                    return i
                
        i -=1




                
print(dec())

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split())
l = [ abs(i - x) for i in list(map(int, input().split()))]
l.sort(reverse=True)
if len(l) == 1:ans = l[0]
else:
  while len(l) != 1:
    l.sort(reverse=True)
    l.append(0)
    l = [ l[i] - l[i+1] for i in range(len(l) - 1)]
    l = list(set(l))
  ans = l[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split())
l = [ abs(i - x) for i in list(map(int, input().split()))]
ans = 1
for i in range(2, min(l) + 1):
  if sum([ d % i for d in l ]) == 0 :  ans = i
print(ans)

Submission status: Time Limit Exceeded

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

rec = []
fil = []
memo_1 = 0
memo_2 = 0
count = 0

for i in range(N[0]):
    mint = X[i] - N[1]
    if mint < 0:
        mint *= -1
    rec.append(mint)
else:
    if len(set(rec)) == 1:
        print(rec[0])
    else:
        while len(set(rec)) != 1:
            a = max(rec)
            rec.remove(max(rec))
            b = max(rec)
            rec.remove(max(rec))

            while a != b:
                if a < b:
                    memo_1 = a
                    a = b
                    b = memo_1
                a = a - b
                count += 1
            else:
                rec.append(a)
                count = 0
        else:
            print(rec[0])

Submission status: Time Limit Exceeded

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

rec = []
fil = []
memo_1 = 0
memo_2 = 0
count = 0

for i in range(N[0]):
    mint = X[i] - N[1]
    if mint < 0:
        mint *= -1
    rec.append(mint)
else:
    if len(set(rec)) == 1:
        print(rec[0])
    else:
        while len(set(rec)) != 1:
            a = max(rec)
            rec.remove(max(rec))
            b = max(rec)
            rec.remove(max(rec))
            while memo_1 != memo_2 or count == 0:
                memo_1 = a - b
                if memo_1 == b and memo_1 != 0:
                    rec.append(memo_1)
                    break
                memo_2 = b - memo_1
                if memo_1 == 0 or memo_2 == 0:
                    print("error")
                    break
            else:
                rec.append(memo_1)
        else:
            print(rec[0])

Submission status: Time Limit Exceeded

Solution code:
count, init = tuple(map(int, input().split(" ")))
Xs = [init] + list(map(int, input().split(" ")))
l = [abs(Xs[i]-Xs[i+1]) for i in range(count)]
for i in range(2, min(l)+1)[::-1]:
    if max(map(lambda x: x%i, l)) == 0:
        print(i)
        exit(0)
print(1)

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

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

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
""" dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))
 """
dist_list = [abs(city-x) for city in city_list]

# TLE対策 mac_D対策
dist_list.sort()
max_D = dist_list.pop(0)

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

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

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

# TLE対策 mac_D対策
dist_list.sort()
max_D = dist_list.pop(0)

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

# TLE対策 mac_D対策
dist_list.sort()
max_D = dist_list[0]

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

# TLE対策 mac_D対策
max_D = sorted(dist_list)[0]

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
f = []
for i in range(1, l+1):
    if l % i == 0:
        f.append(i)
for i in range(len(f), 0, -1):
    d = True
    for item in c:
        if item % f[i-1] != 0:
            d = False
    if d:
        print(f[i-1])
        break

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l, 0, -1):
    d = True
    for item in c:
        if item % i != 0:
            d = False
    if d:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
x = sorted(map(lambda s: abs(int(s) - X), input().split()))
x = x[0:1] + [x[i] for i in range(1, len(x)) if x[i] != x[i-1]]

for d in range(x[0], 1, -1):
    for xi in x:
        if xi % d != 0:
            break
    else:
        print(d)
        exit()
print(1)

Submission status: Time Limit Exceeded

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

for d in range(x[0], 1, -1):
    for xi in x:
        if xi % d != 0:
            break
    else:
        print(d)
        exit()
print(1)

Submission status: Time Limit Exceeded

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

def main():    
    N,X = map(int,input().split())
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    while len(x) > 1:
#        print(x[0],x[1])
        y = gcd(x[0],x[1])
        x.pop(0)
        x.pop(0)
        x.insert(0,y)
#        print(x)
    print(x[0])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
if __name__ == '__main__':
    NX = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    X.append(NX[1])
    # if len(X) == 1:
    #     print(abs(X[0]-NX[1]))
    #     sys.exit(0)

    X.sort()
    diff = [X[i] - X[i-1] for i in range(1, len(X))]
    D = min(diff)
    while any(np.array(diff)%D):
        D -= 1
    print(D)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

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

	if b:
		return gcd(b, a % b)
	else:
		return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

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

# li = [i for i in li if i]
li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

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

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

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

# li = [i for i in li if i]
li = sorted(li, reverse=True)
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

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

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

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

# li = [i for i in li if i]
li.reverse()
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(500000)

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

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

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

# li = [i for i in li if i]
li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

Submission status: Time Limit Exceeded

Solution code:
def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]
    if not x in points:
        points.append(x)

    buf = [abs(points[i + 1] - points[i]) for i in range(len(points) - 1)]
    while len(buf) > 1:
        buf = [euclid(buf[i + 1], buf[i]) for i in range(len(buf) - 1)]

    print(buf[0])

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

Solution code:
# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

nearest_city = getNearestValue(city_list, x)

max_D = abs(nearest_city-x)
for xx in reversed(range(1, max_D+1)):
    flag = True
    for city in city_list:
        if (abs(city - x) % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

Submission status: Time Limit Exceeded

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

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

z = list(set(y))

for r in range(z[0],0,-1):
    p=0
    for j in range(1,len(z)-1):
        if z[j]%r!=0:
            p=p+1
    if p==0:
        break
print(r)

Submission status: Time Limit Exceeded

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

for i in range(N):
    y.append(x[i+1]-x[i])
y.sort()
z = list(set(y))

for r in range(z[0],0,-1):
    p=0
    for j in range(1,len(z)-1):
        if z[j]%r!=0:
            p=p+1
    if p==0:
        break
print(r)