Problem:


Score : 300 points

Problem Statement

There is a box containing N balls. The i-th ball has the integer A_i written on it.
Snuke can perform the following operation any number of times:

Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.

Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq K \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.

Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5.
Next, take out 3 and 5, and return them back along with abs(3-5)=2.
Finally, take out 9 and 2, and return them back along with abs(9-2)=7.
Now we have 7 in the box, and the answer is therefore POSSIBLE.

Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.

Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

The box already contains 11 before we do anything. The answer is therefore POSSIBLE.

Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE



Sample input:
3 7
9 3 4


Sample output:
POSSIBLE

Submission status: Accepted

Solution code:
import fractions
N,K=map(int,input().split())
A=list(map(int,input().split()))
gc=A[0]
for i in range(1,N):
    gc=fractions.gcd(gc,A[i])
#print(gc)
A.sort()
if (K<=A[N-1])and(((A[N-1]-K)%gc)==0)and((K%gc)==0):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    over = []
    for a in A:
        if a >= K:
            over.append(a)

    if len(over) == 0:
        print("IMPOSSIBLE")
        exit(0)
    if min(over) == K:
        print("POSSIBLE")
        exit(0)

    while True:
        min_A = min(A)
        B = []
        for a in A:
            r = a % min_A
            if r != 0:
                B.append(r)
        if len(B) == 0:
            print("IMPOSSIBLE")
            exit(0)
        else:
            min_B = min(B)
            for oa in over:
                if (oa - K) % min_B == 0:
                    print("POSSIBLE")
                    exit(0)
            A = A + B

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = A[0]
for i in range(1, N):
  g = gcd(g, A[i])

if K > max(A):
  print("IMPOSSIBLE")
elif K % g != 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
key = a[0]
for i in range(1, n):
  key = gcd(key, a[i])

if k > max(a):
  ans = False
elif key == 1:
  ans = True
elif k%key == a[0]%key:
  ans = True
else:
  ans = False

if ans:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
def check():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K > max(A):
        return False
    g = A[0]
    for i in range(1,N):
        g = gcd(g,A[i])
    if K%g != 0:
        return False
    return True
if check():
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import fractions
N, K = map(int, input().split())
A = list(map(int, input().split()))
G = A[0]
for i in range(1,N):
  G = fractions.gcd(G,A[i])
if (K < max(A) and K % G == 0) or K == max(A):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

d = reduce(gcd, A)
print('POSSIBLE' if K <= max(A) and K % d == 0 else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
INF = 10 ** 20
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left
from functools import reduce
from fractions import gcd

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))

    if k > max(a):
        print('IMPOSSIBLE')
        return

    G = reduce(gcd,a)
    if k%G == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import fractions

if K > max(A):
    print('IMPOSSIBLE')
else:
    g = A[0]
    for i in range(N - 1):
        g = fractions.gcd(g, A[i + 1])
    #print(g)

    ok = False
    for val in A:
        if val >= K and (val - K) % g == 0:
            ok = True
    if ok:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])
print('POSSIBLE' if (K <= A[-1] and K % g == 0) else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd

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

def gcd_all():
    x = A[0]
    for i in range(1, N):
        x = gcd(x, A[i])
    return x

def solve():
    if K > A[-1]:
        return False
    return K % gcd_all() == 0

print('POSSIBLE' if solve() else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, k = map(int, readline().split())
a = list(map(int, readline().split()))
gcd_a = a[0]
for i in range(1, n):
    gcd_a = gcd(a[i], gcd_a)
if k % gcd_a == 0 and k <= max(a):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
n,k=map(int,input().split())
A=list(map(int,input().split()))
if k>max(A):
    print('IMPOSSIBLE')
else:
    a=A[0]
    for i in range(n):
        a=gcd(a,A[i])
    if a==1 or k%a==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
if k>A[-1]:
    print('IMPOSSIBLE')
else:
    a=A[0]
    for i in range(n):
        a=gcd(a,A[i])
    if a==1:
        print('POSSIBLE')
    else:
        if k%a==0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
M = a[0]
g = a[0]
for i in range(1,n):
    M = max(M,a[i])
    g = gcd(g,a[i])
if k <= M and k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
g = A[0]
for a in A[1:]:
    g = gcd(a, g)
for a in A:
    if a >= K and (a - K) % g == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions as f

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

if K <= A[-1]:
    GCD = A[0]
    for i in range(1, N):
        GCD = f.gcd(GCD, A[i])
    if K % GCD == 0:
        POSSIBLE = True

if POSSIBLE:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,k = m()

a = l()

po = gcd_list(a)

fl = 0

for i in range(n):
    if a[i] >= k and (a[i]-k) % po == 0:
        fl = 1
if fl:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
# あーもうめちゃくちゃだよ
if tmp == 1:
    print("POSSIBLE")
    exit()
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
# あーもうめちゃくちゃだよ
if flag and k % tmp != 0:
    print("IMPOSSIBLE")
    exit()

even_flag, odd_flag = False, False
for a in arr:
    if a % 2 == 1:
        odd_flag = True
    else:
        even_flag = True

# あーもうめちゃくちゃだよ
if odd_flag:
    if k % 2 == 0 and not even_flag:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
    exit()

# あーもうめちゃくちゃだよ
if k % 2 == 1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
#操作の中で値が増えることはないため、max(a) < kだった場合は無理 
n,k = map(int, input().split())
a = list(map(int, input().split()))
gcd_a = a[0]
for i in range(n):
    gcd_a = gcd(gcd_a,a[i])
if k % gcd_a == 0 and k <= max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions
N,K=map(int,input().split())
a=list(map(int,input().split()))
bef=a[0]
gcd=a[0]
max_=a[0]
for i in range(1,N):
    if max_<a[i]:
        max_=a[i]
    gcd=fractions.gcd(gcd,a[i])
if max_<K:
    print("IMPOSSIBLE")
else:
    if K%gcd==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
n, k = map(int, input().split())
a = list(map(int, input().split()))

a_gcd = a[0]
for i in range(1, n):
    a_gcd = gcd(a_gcd, a[i])
ans = True
if k > max(a):
    ans = False
if k % a_gcd != 0:
    ans = False
if k in a:
    ans = True

print('POSSIBLE' if ans else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc018/tasks/agc018_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


from fractions import gcd
N, K = read_ints()
A = read_ints()
# 結論からいうとKがminとmaxの間でかつ、gcd(A)の倍数であるならば、必ずKを構成することができる。
# ∵ある2要素a,bからはgcd(a,b)の倍数しか作ることができない。これをすべての要素に適応するだけ。

g = 0  # gcdの単位元
for a in A:
    g = gcd(g, a)

if min(A) <= K <= max(A) and K % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
max_A = max(A)
A.sort()

if(max_A < K):
    print("IMPOSSIBLE")
else:
    num = 10**10
    for i in range(N-1):
        if(min(num, abs(A[i]-A[i+1]))):
            num = min(num, abs(A[i]-A[i+1]))

    for i in range(N):
        if(A[i] < K):
            continue
        if((K-A[i])%num == 0):
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
m=A[-1]
if m<K:
    print("IMPOSSIBLE")
else:
    ans=A[0]
    for i in range(1,N):
        ans=fractions.gcd(ans,A[i])
    if fractions.gcd(K,ans)==ans:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
N,K=map(int,input().split(' '))
A=sorted(list(map(int,input().split(' '))))
G=A[0]
for i in A[1:]:
    G=gcd(G,i)
if A[-1] >= K and K%G==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

M = max(A)


def mgcd(x):
    return reduce(gcd, x)


if M < K:
    print("IMPOSSIBLE")
elif K in A:
    print("POSSIBLE")
else:
    G = mgcd(A)
    if K % G == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions

N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
A.sort()
diff = 10 ** 9

if max(A) < K:
    print('IMPOSSIBLE')
else:
    gcd = max(A)
    for i in range(N):
        gcd = fractions.gcd(gcd, A[i])

    if K % gcd == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Accepted

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

n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
for i in range(1, n):
    a[i] = gcd(a[i], a[i - 1])
print("POSSIBLE" if k % a[n - 1] == 0 and k <= m else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions

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

n = A[0]
for i in range(N):
    n = fractions.gcd(n, A[i])

if K<=max(A) and K%n==0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Accepted

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

def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

g = As[0]
for a in As:
    g = gcd(g, a)

for a in As:
    if a >= K and (a-K) % g == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
#AGC018-A
if True:
    import fractions

    N,K=map(int,input().split())
    A=[int(i) for i in input().split()]
    MAX=max(A)
    GCD=A[0]
    for a in A:
        GCD=fractions.gcd(a,GCD)
    if K%GCD==0 and K<=MAX:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=sorted(map(int,input().split()))
def gcd(x,y):
  if y==0:return x
  return gcd(y,x%y)
ans=""
s=0
for i in l:
  s=gcd(i,s)
  if s==1:break
else:
  if k%s!=l[-1]%s:
    ans="IM"
if l[-1]<k:ans="IM"
print(ans+"POSSIBLE")

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


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


def gcd_n(a, n):
    ans = a[0]
    for i in range(1, n):
        ans = gcd(ans, a[i])
    return ans


def main():
    N, K = MI()
    A = LI()
    A = sorted(A)
    mx = max(A)

    ret = gcd_n(A, N)

    if mx < K:
        print('IMPOSSIBLE')
        return

    if K % ret == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

    # A = set(A)
    # while True:
    #     c = len(A)
    #     for p in combinations(A, 2):
    #         A.add(abs(p[0] - p[1]))

    #     if c == len(A):
    #         break

    # print(A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = sorted(map(int, input().split()))

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


smallest_ball = A[0]
for a in A[1:]:
    smallest_ball = gcd(smallest_ball, a)

print("POSSIBLE" if (A[-1]-k) %
      smallest_ball == 0 and k <= A[-1] else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
INF = 10**9+1
diff = INF
for x, y in zip(A, A[1:]):
    z = abs(x-y)
    if z > 0:
        diff = min(diff, z)

MAX = A[-1]
ans = False
for a in A:
    if a-k < 0:
        continue
    x, r = divmod((a-k), diff)
    if r == 0:
        ans = True
        break
print("POSSIBLE" if ans else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions
N, K = map(int, input().split())
arr = list(map(int, input().split()))
t = arr[0]
for i in range(1,N):
    t = fractions.gcd(t,arr[i])
if max(arr) < K or K % t != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Accepted

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
if max(A) < K:
    print('IMPOSSIBLE')
    exit()
res = A[0]
for i in range(1, N):
    a = A[i]
    b = res
    if a < b:
        a, b = b, a
    res = gcd(a, b)
if K % res == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


def main():
    balls, target = map(int, input().split())
    numbers = [int(x) for x in input().split()]
    numbers.sort()
    numbers_gcd = reduce(gcd, numbers)
    print("POSSIBLE" if target % numbers_gcd == 0 and target <= numbers[-1] else "IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N,K = map(int,input().split())
    A = set(map(int,input().split()))
    A = list(A)
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = set(map(lambda x:abs(x-K),A))
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()

    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()

    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()

    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mn=a[0]
mm=a[0]+1
mx=a[-1]
bool=1
b=[mx+1 for _ in range(len(a)-1)]
if mx<k:
  print("IMPOSSIBLE")
  exit()
if k in a:
  print("POSSIBLE")
  exit()
while bool==1:
  a=list(set(a))
  a.sort()
  b=[mx+1 for _ in range(len(a)-1)]
  p=a[0]
  for i in range(1,len(a)):
    x=a[i]
    b[i-1]=x-p
    if x>p:
      mm=min(mm,x-p)
    p=x
  if mm==mn:
    bool=0
  else:
    mn=mm
  b=[x for x in b if x!=0]
  a.extend(b)

#print(a,mn,mx,b)
if mn==1:
  print("POSSIBLE")
  exit()
elif (mx-k)%mn==0:
  print("POSSIBLE")
  exit()
else:
  print("IMPOSSIBLE")
  exit()



print(a,mn,mx,b)

Submission status: Accepted

Solution code:
import sys
import fractions

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

if k > max(a) :
  print('IMPOSSIBLE')
  sys.exit()
if k in a :
  print('POSSIBLE')
  sys.exit()
  
g = fractions.gcd(a[0],a[1])
for i in range(2,n) :
  g = fractions.gcd(g,a[i])
  
if k%g == 0 :
  print('POSSIBLE')
else :
  print('IMPOSSIBLE')

Submission status: Accepted

Solution code:

N, K = map(int, input().split())
#print(K)

A = list(set((map(int, input().split()))))

if len(A) == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    A.sort()

    #print(A)

    a = A[0]
    lenA = len(A)
    for i in range(1,lenA):
        if A[i]%a > 0:
            b = A[i]
            break
        if i == lenA-1:
            b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)

Submission status: Accepted

Solution code:

from fractions import gcd
from functools import reduce

def solve():
  n, k = list(map(int, input().split()))
  a = list(map(int, input().split()))

  l = reduce(gcd, a)
  max_a = reduce(max, a)
  if k % l == 0 and max_a >= k:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")

  return
 
if __name__ == "__main__":
  solve()

Submission status: Accepted

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

n, k = map(int, input().split())
A = list(map(int, input().split()))
maxA = max(A)

l = A.pop()
for a in A:
  l = gcd(l, a)

print('POSSIBLE' if k % l == 0 and maxA >= k else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar 22 17:06:57 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
a = na()

def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m % n)

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

m = max(a)
if g == 1 and k <= m:
    print("POSSIBLE")
elif k % g == 0 and k <= m:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
    
n , k = map(int,input().split())
a = list(map(int,input().split()))
fl = ""

if k > max(a):
    fl = "IMPOSSIBLE"

else:
    g = a[0]
    for i in range(n-1):
        g = gcd( g , a[i+1] )
        
    if k % g == 0:
        fl = "POSSIBLE"
    else:
        fl = "IMPOSSIBLE"
        
print(fl)

Submission status: Accepted

Solution code:
import sys
N,K=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a,b):
  if a==b:
    return a
  else:
    a,b=max(a,b),min(a,b)
    if a%b==0:
      return b
    else:
      return gcd(b,a%b)
if N==1:
  if K==a[0]:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  sys.exit()
          
for i in range(N-1):
  if i==0:
    tmp=gcd(a[i],a[i+1])
  else:
    tmp=gcd(tmp,a[i+1])
if tmp==1:
  if K<=max(a):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
else:
  if K<=max(a):
    if K%tmp==0:
      print('POSSIBLE')
    else:
      print('IMPOSSIBLE')
  else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

#if K <= max(A) and K % reduce(gcd, A) == 0:
if K <= max(A) and K % gcd_list(A) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

if K <= max(A) and K % reduce(gcd, A) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
import functools

def gcd_list(l):
    return functools.reduce(gcd, l)

def solve():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    d = gcd_list(A)
    ret = False
    if K > max(A):
        print('IMPOSSIBLE')
        return
    
    for a in A:
        if (a-K)%d == 0:
            ret = True
            break
            
    print('POSSIBLE' if ret else 'IMPOSSIBLE')
    
solve()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

g = reduce(gcd, A)
print('IMPOSSIBLE' if K > max(A) or K % g else 'POSSIBLE')

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()


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


n, k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for i in range(1, n):
    g = gcd(g, a[i])
if k % g == 0 and max(a) >= k:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
g=a[0]
for i in range(1,n):
    g=gcd(g,a[i])
if k>max(a):
    print("IMPOSSIBLE")
else:
    if k%g==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
if max(a) < k:
    print("IMPOSSIBLE")
    exit()
x = a[0]
for i in range(1,n):
    x = gcd(x, a[i])

print("IMPOSSIBLE" if k % x else "POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
if max(a) < k:
    print("IMPOSSIBLE")
    exit()
x = a[0]
for i in range(1,n):
    x = gcd(x, a[i])

for i in range(n):
    if (a[i] - k) % x == 0:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd

N,K = map(int, input().split())
A = [int(i) for i in input().split()]

M = max(A)

G = 0
for a in A:
    G = gcd(G, a)

if K % G == 0 and K <= M:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()

if A[-1] < K:
    print("IMPOSSIBLE")
    exit()

from bisect import bisect_left

flag = False
for i in range(N):
    if A[i] == K:
        flag = True
    
    idx = bisect_left(A, K - A[i])
    if idx < N and i != idx and A[idx] == K - A[i]:
        flag = True

if flag:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
if A[-1] < K:
    print("IMPOSSIBLE")
    exit()
if K in A:
    print("POSSIBLE")
    exit()
from fractions import gcd
n = A[0]
for i in range(1,N):
    n = gcd(A[i],n)
if K % n == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()], reverse=True)

for v in A:
    if K==v:
        print("POSSIBLE")
        quit()
if K > A[0]:
    print("IMPOSSIBLE")
    quit()

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

for v in d:
    if v:
        K %= v

if K:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
while N > 1:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = [int(s) for s in input().split()]

if k > max(a):
  print('IMPOSSIBLE')
elif min(a) == 1 or k in a:
  print('POSSIBLE')
else:
  divmax = min(a)
  divval = 1
  for div in range(divmax):
    for x in a:
      if x % (div+1) != 0:
        break
    else:
      divval = div + 1
  if k % divval == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
def gcd(a,b):
	if(a==0 or b==0):
		return a+b
	return gcd(b,a%b)
n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
val=0
for c in l:
	val = gcd(val,c)
if(k%val==0 and k<=max(l)):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    x = a[0]
    for v in a:
        if v % x == 0:
            continue
        x = v % x
    f = False
    for v in a:
        if k <= v and (v-k)%x == 0:
            f = True
    if f:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions

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

if n == 1:
    print("POSSIBLE" if arr[0] == k else "IMPOSSIBLE")
else:
    # 最大公約数
    gcd = arr[0]
    for num in arr[1:]:
        gcd = fractions.gcd(gcd, num)

    print("POSSIBLE" if (k % gcd == 0 and k <= max(arr)) else "IMPOSSIBLE")