Problem p03651 (python)

Fixed submission:

from fractions import gcd


N, K = map(int, raw_input().split())
A = sorted(list(map(int, raw_input().split())))


if K > A[-1]:
    print('IMPOSSIBLE')
else:
    flag = True
    tmp = reduce(gcd, A)
    if tmp != 1:
        flag = False
    for a in A:
        if a == K or (K - a) % tmp == 0:
            flag = True
            break
    if flag:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
from fractions import gcd


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


if K > A[-1]:
    print('IMPOSSIBLE')
else:
    flag = True
    tmp = reduce(gcd, A)
    if tmp != 1:
        flag = False
    for a in A:
        if a == K or (K - a) % tmp == 0:
            flag = True
            break
    if flag:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))


if K > A[-1]:
    print('IMPOSSIBLE')
else:
    flag = True
    for i in range(N - 1):
        if A[i] % (A[i + 1] - A[i]) == 0 or \
           (A[i + 1] - A[i]) % A[i] == 0 or \
           A[i + 1] % (A[i + 1] - A[i]) == 0:
            flag = False
            break
    if flag:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))


if K > A[-1]:
    print('IMPOSSIBLE')
else:
    flag = True
    for i in range(N - 1):
        if A[i] % (A[i + 1] - A[i]) == 0 or \
           (A[i + 1] - A[i]) % A[i] == 0:
            flag = False
            break
    if flag:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# import numpy as np

# while True:
# A, B = np.random.randint(100) * 2 + 1, np.random.randint(100) * 2 + 1
# if A < B:
#     A, B = B, A
# ori_a, ori_b = A, B
# while True:
#     print(A, B)
#     mid = abs(A - B)
#     A, B = mid, B
#     if A < B:
#         A, B = B, A
#     # print(A, B)
#     if B == 1:
#         print("clear")
#         break
#     elif B == 0:
#         print(ori_a, ori_b, "wrong")
#         break


def eratos(n):
    if n <= 1:
        return []
    used = [False] * n
    used[0] = used[1] = True
    primes = []
    for i in range(n):
        if used[i] is False:
            primes.append(i)
            for j in range(i * 2, n, i):
                used[j] = True
    return primes


N, K = map(int, input().split())
A = list(map(int, input().split()))
max_a = max(A)
primes = eratos(K + 1)

defactors = []
x = A[0]
for prime in primes:
    if x == 1:
        continue
    while x % prime == 0:
        defactors.append(prime)
        x //= prime
cand = list(set(defactors))

if K > max_a:
    print('IMPOSSIBLE')
else:
    for c in cand:
        next_a = []
        for i in range(len(A)):
            if (A[i] % c != 0):
                next_a.append(A[i])
        A = next_a
    # print(list(filter(lambda x: x != 0, A)))
    if len(list(filter(lambda x: x != 0, A))):
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')