Problem: 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.

Submission attempts (in order):
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]

num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

flag=True
for i in range(min_distance,-1):
    for j in range(n):
        if first_distance[j]%i!=0:
            flag=False
            break

    if flag:
        ans=i
        print(ans)
        break

num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]

num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

flag=True
for i in range(min_distance,-1):
    for j in n:
        if first_distance[j]%i!=0:
            flag=False

    if flag:
        print("i")
        break


num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)


for i in range(min_distance,0,-1):
    Can_go_list=list(map(lambda z: 1 if z % i == 0 else 0,first_distance))

    if 1 not in Can_go_list:
        ans = i
        print(ans)
        break

num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)


for i in range(min_distance,0,-1):
    Can_go_list=list(map(lambda z:z%i,first_distance))

    if 0 not in Can_go_list:
        ans = i
        print(ans)
        break

num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

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

gcd=gcd(first_distance[0],first_distance[1])
for i in range(2,n):
    gcd=gcd(gcd,first_distance[i])
print(gcd)

num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

gcd=gcd(first_distance[0],first_distance[1])
for i in range(2,n):
    gcd=gcd(gcd,first_distance[i])
print(gcd)

num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

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


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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted