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: Time Limit Exceeded

Solution code:
#! cat input | python3 main.py

n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    __import__("sys").exit()
a.sort()
ma = max(a)
def isfact(n):
    if n == 2: return True
    for i in (2, n**0.5 + 1):
        if n % i == 0:
            return False
    return True
def calcfacts():
    r = []
    for i in range(2, 10**5):
        if isfact(i):
            r.append(i)
    return r
allfacts = calcfacts()

def prim_fact(n):
    facts = []
    ti = 0
    t = allfacts[ti]
    nn = n ** 0.5 + 1
    while True:
        if n % t == 0:
            facts.append(t)
            n //= t
        else:
            ti += 1
            t = allfacts[ti]
        if t >= n or t > nn:
            if n != 1:
                facts.append(n)
            break
    return facts


def f(a, k, ma):
    minv = float("inf")
    for i, v in enumerate(a[1:]):
        if v - a[i] != 0:
            minv = min(minv, v - a[i])
    minv = min(minv, a[0])

    sets = []
    setn = set()
    for v in a:
        s = set(prim_fact(v))
        sets.append(s)
        for i in s: setn.add(i)
    for v in setn:
        for s in sets:
            if v not in s:
                break
        else:
            minv = min(minv, v)
            break
    else:
        return False

    if minv == 1:
        return False

    a = a[:]
    for i in range(0, ma + minv, minv):
        if i == k:
            return False
        if i < a[0]:
            continue
        if i == a[0]:
            del a[0]
        else:
            return False
    return True

if ma < k:
    print("IMPOSSIBLE")
elif f(a, k, ma):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

def abs_sub(n1,n2):
    s = abs(n1 - n2)
    return s

def main():
    N, K = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    #print(a)
    bef_a = copy.deepcopy(a)
    while(True):
        a_comb = list(itertools.combinations(a,2))  
        #print(a_comb)
        for data in a_comb:
            tmp = abs_sub(data[0],data[1])
            #print(tmp)
            a.append(tmp)
        a = list(set(a))
        #print(a)
        if(K in a):
            print("POSSIBLE")
            break
        elif(len(bef_a) == len(a)):
            print("IMPOSSIBLE")
            break
        
        bef_a = copy.deepcopy(a)
         
if(__name__ =="__main__"):
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

if K in an:
    print('POSSIBLE')
    exit()

while True:
    comb=combinations(an, 2)
    prean = an[:]
    for it in comb:
        a = abs(it[0] - it[1])
        if a in an:
            continue
        if a == K:
            print('POSSIBLE')
            exit()
        an.append(a)
    if len(an) == len(prean):
        print('IMPOSSIBLE')
        break

Submission status: Time Limit Exceeded

Solution code:
#! cat input | python3 main.py

n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    __import__("sys").exit()
a.sort()
ma = max(a)
def prim_fact(n):
    facts = []
    t = 2
    nn = n ** 0.5 + 1
    while True:
        if n % t == 0:
            facts.append(t)
            n //= t
        else:
            t += 1
        if t > n or t > nn:
            if n != 1:
                facts.append(n)
            break
    return facts


def f(a, k, ma):
    minv = float("inf")
    for i, v in enumerate(a[1:]):
        if v - a[i] != 0:
            minv = min(minv, v - a[i])
    minv = min(minv, a[0])

    sets = []
    setn = set()
    for v in a:
        s = set(prim_fact(v))
        sets.append(s)
        for i in s: setn.add(i)
    for v in setn:
        for s in sets:
            if v not in s:
                break
        else:
            minv = min(minv, v)
            break
    else:
        return False

    if minv == 1:
        return False

    a = a[:]
    for i in range(0, ma + minv, minv):
        if i == k:
            return False
        if i < a[0]:
            continue
        if i == a[0]:
            del a[0]
        else:
            return False
    return True

if ma < k:
    print("IMPOSSIBLE")
elif f(a, k, ma):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
#! cat input | python3 main.py

n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    __import__("sys").exit()
a.sort()
ma = max(a)
def prim_fact(n):
    facts = []
    t = 2
    while True:
        if n % t == 0:
            facts.append(t)
            n //= t
        else:
            t += 1
        if t > n:
            if n != 1:
                facts.append(n)
            break
    return facts


def f(a, k, ma):
    minv = float("inf")
    for i, v in enumerate(a[1:]):
        if v - a[i] != 0:
            minv = min(minv, v - a[i])
    minv = min(minv, a[0])

    sets = []
    setn = set()
    for v in a:
        s = set(prim_fact(v))
        sets.append(s)
        for i in s: setn.add(i)
    for v in setn:
        for s in sets:
            if v not in s:
                break
        else:
            minv = min(minv, v)
            break
    else:
        return False

    if minv == 1:
        return False

    a = a[:]
    for i in range(0, ma + minv, minv):
        if i == k:
            return False
        if i < a[0]:
            continue
        if i == a[0]:
            del a[0]
        else:
            return False
    return True

if ma < k:
    print("IMPOSSIBLE")
elif f(a, k, ma):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, raw_input().split(" "))
s = set(map(int, raw_input().split(" ")))

if k in s:
  print "POSSIBLE"
  exit()
while 1:
  ar = sorted(s)
  changed = False
  prev = None
  deltas = [0]
  for a in ar:
    if not prev:
      prev = a
      continue
    v = a - prev
    for i in xrange(len(deltas)):
      n = deltas[i] + v
      deltas[i] += v
      if n not in s:
        s.add(n)
        changed = True
    deltas.append(v)
    prev = a
  if k in s:
    print "POSSIBLE"
    exit()
  elif not changed:
    print "IMPOSSIBLE"
    exit()

Submission status: Time Limit Exceeded

Solution code:
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
ans = 0
if k in l:
    print("POSSIBLE")
    exit()
if n == 1:
    l[0] == k

la = []
while True:
    for i in range(n):
        x = l[i] - k
        xx = l[i] + k
        if x in l or xx in l :
            ans = 1
            break
        else:
            if x not in la:
                la.append(x)
            if xx not in la:
                la.append(x)
        for j in range(i,n):
            a = abs(l[j] - l[i])
            if a == k:
                ans = 1
                break
            else:
                if a in la:
                    ans = 1
                    break
                if a not in l:
                    l.append(a)
                x = a - k
                xx = a + k
                if x in l or xx in l :
                    ans = 1
                    break
                else:
                    if x not in la:
                        la.append(x)
                    if xx not in la:
                        la.append(x)

    _n = n
    n = len(l)
    if n == _n:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
def factors(n):  # generator that computes factors
    k=1
    while k * k < n:        # while k < sqrt(n)
        if n % k == 0:
            yield k
        k += 1
    if k * k == n:      # special case if n is perfect square
        yield k

N,K=map(int,input().split())
l1=list(map(int,input().split()))
if K in l1:
    print("POSSIBLE")
    sys.exit()
s1=set(math.fabs(K-ll) for ll in l1 if ll>K)
s2=set([])
for i in s1:
    s2=s2|set(factors(i))

for i in s2:
    for j in l1:
        if (i+j) in l1:
            print("POSSIBLE")
            sys.exit()
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
ans = 0
if k in l:
    print("POSSIBLE")
    exit()

while True:
    for i in range(n-1):
        for j in range(i+1,n):
            a = abs(l[j] - l[i])
            if a == k:
                ans = 1
                break
            else:
                if a not in l:
                    l.append(a)
    _n = n
    n = len(l)
    if n == _n:
        break

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

Submission status: Time Limit Exceeded

Solution code:
# A(300)
import math
import numpy as np
N, K = map(int, input().split())
A_np = np.array(list(map(int, input().split())))

if K > A_np.max():
    print("IMPOSSIBLE")
    
else:    
    L = 10**9+1
    l = math.ceil(math.sqrt(L)) + 1

    isprime = np.ones(l)
    isprime[0] = 0
    isprime[1] = 0
    for i in range(2, l):
        if isprime[i]:
            isprime[2*i:l:i] = 0


    # find LCM
    LCM = 1
    for p in range(l):
        if isprime[p]:
            while True:
                if (A_np % p).sum() == 0:
                    A_np = A_np // p
                    LCM *= p
                else:
                    A_np[A_np % p == 0] = A_np[A_np % p == 0] // p
                    break


    # rare case 
    # large p in common
    if A_np.max() == A_np.min():
        LCM *= A_np.max()
    else:
        LCM = 1
        
    if K % LCM == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

if K in an:
    print('POSSIBLE')
    exit()

while True:
    comb=combinations(an,2)
    prean = an[:]
    for it in comb:
        a = abs(it[0] - it[1])
        if a == K:
            print('POSSIBLE')
            exit()
        if a not in an:
          an.append(a)
    if len(an) == len(prean):
        print('IMPOSSIBLE')
        break

Submission status: Time Limit Exceeded

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

if K in A:
    print("POSSIBLE")
elif K > max(A):
    print("IMPOSSIBLE")
else:
    n = 0
    while n != len(A):
        n = len(A)
        addset = {abs(i - j) for i in A for j in A}
        A = A.union(addset)
        if K in A:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def add_diff(A, K):
    comb_list = list(itertools.permutations(A, 2))
    for comb in comb_list:
        if abs(comb[0] - comb[1]) == K:
            print("POSSIBLE")
            return 0
        A.add(abs(comb[0] - comb[1]))

def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    K = int(args[1])
    A = set()
    args = sys.stdin.readline().split()
    for i in range(N):
        if int(args[i]) == K:
            print("POSSIBLE")
            sys.exit()
        A.add(int(args[i]))

    while True:
        list_len = len(A)
        if add_diff(A, K) == 0:
            sys.exit()
        if list_len == len(A):
            break

    print("IMPOSSIBLE")

main()

Submission status: Time Limit Exceeded

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

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

ans = False

cnt = 0
prev_len = 0
prepre_len = 0

while(1):
    if K in A:
        ans = True
        break
        
    
     
    if cnt == 0:
        for i in range(len(A)-1):
            for j in range(i+1, len(A)):
                tmp = abs(A[i] - A[j])
#                 print(tmp)
                if tmp not in A:
                    A.append(tmp)
                    
    else :
        for i in range(len(A)-1):
            for j in range(prepre_len, len(A)):
                tmp = abs(A[i] - A[j])
#                 print(tmp)
                if tmp not in A:
                    A.append(tmp)
                    
    if len(A) == prev_len:
        ans = False
        break
                    
#     print(A)
    
    prepre_len = prev_len
    prev_len = len(A)
    cnt += 1
    
    
if ans == True:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

if K in A:
    print("POSSIBLE")
elif K > max(A):
    print("IMPOSSIBLE")
else:
    n = 0
    while n != len(A):
        n = len(A)
        addset = set()
        for i in A:
            for j in A:
                addset.add(abs(i-j))

        A = A.union(addset)
        if K in A:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

def calc(seq, target):
    if target in seq:
        return 'POSSIBLE'
    if max(seq) < target:
        return 'IMPOSSIBLE'
    dif = []
    target_diff = []
    for idx,s in enumerate(seq):
        if target < s:
            target_diff.append(s - target)
        if idx==0:
            continue
        d = abs(s-seq[idx-1])
        if d == 1:
            return 'POSSIBLE'
        dif.append(d)
    dif = list(set(dif))
    for d in dif:
        for td in target_diff:
            if td%d == 0:
                return 'POSSIBLE'
    return 'IMPOSSIBLE'

print(calc(As, K))

Submission status: Time Limit Exceeded

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

def calc(seq, target):
    if target in seq:
        return 'POSSIBLE'
    if max(seq) < target:
        return 'IMPOSSIBLE'
    dif = []
    target_diff = []
    for idx,s in enumerate(seq):
        if target < s:
            target_diff.append(s - target)
        if idx==0:
            continue
        dif.append(abs(s-seq[idx-1]))
    dif = list(set(dif))
    for d in dif:
        for td in target_diff:
            if td%d == 0:
                return 'POSSIBLE'
    return 'IMPOSSIBLE'

print(calc(As, K))

Submission status: Memory Limit Exceeded

Solution code:
from sys import stdin
import fractions
n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
if k > li[-1]:
    print("IMPOSSIBLE")
    exit()
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(li)
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")

Submission status: Accepted

Solution code:

from math import gcd
from functools import reduce


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

    _max = max(A)
    g = reduce(gcd, A)

    if K <= _max and K % g == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import numpy as np
from math import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k in a:
    print("POSSIBLE")
    exit()
x=np.gcd.reduce(a)
if x==1:
    print("POSSIBLE")
else:
    if k<max(a) and k%x==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

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

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

if k%g == 0 and k <= max(a):
  print ('POSSIBLE')
else:
  print ('IMPOSSIBLE')

Submission status: Accepted

Solution code:
N,K,*A=map(int,open(0).read().split())
from math import*
c=A[0]
for a in A:
    c=gcd(c,a)
print('IM'*(K%c>0 or K>max(A))+'POSSIBLE')

Submission status: Accepted

Solution code:
from math import gcd
n, k = map(int, input().split())
a = list(set(map(int, input().split())))
a.sort(); b = a[0]
for i in range(1, len(a)): b = gcd(b, a[i])
if len(a) == 1:
    print("POSSIBLE") if k == a[0] else print("IMPOSSIBLE")
else:
    print("POSSIBLE") if k <= a[-1] and k%b == 0 else print("IMPOSSIBLE")

Submission status: Accepted

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

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

if k in a or (k%g==0 and k<=max(a)):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

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

from fractions import gcd
from functools import reduce

g = reduce(gcd, a)

if max(a) >= k and k%g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from math import gcd
n, k = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]

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

Submission status: Accepted

Solution code:
import math

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

if K > A[-1]:
    print('IMPOSSIBLE')
    exit()

keep = A[0]
for i in range(1, N):
    keep = math.gcd(keep, A[i])
if K % keep == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
yes="POSSIBLE" ; no="IMPOSSIBLE"
import numpy as np
q= np.gcd.reduce(A)
if k%q==0 and max(A)>=k:
    print(yes)
else:
    print(no)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,K=mint()
A=lint()
judge(K<=max(A) and K%lgcd(A)==0,['POSSIBLE','IMPOSSIBLE'])

Submission status: Accepted

Solution code:
import math
from functools import reduce
N, K = map(int, input().split())
A = list(map(int, input().split()))

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

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

Submission status: Accepted

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

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

g=0
max_a=0
for a in A:
	g=gcd(g, a)
	max_a=max(max_a, a)

if K%g==0 and K<=max_a:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


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

# Greatest Common Divisor(Euclidean algorithm)


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def main():
    n, k = input_int_list()
    A = input_int_list()
    A_max = max(A)
    # Aの最大値よりkが大きい場合は不可
    if k > A_max:
        print("IMPOSSIBLE")
        return

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

    if k % A_gcd == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n = int(input())
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    g = reduce(gcd, a)

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

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
1
4
-1 1 1 -1

"""

Submission status: Accepted

Solution code:
from math import gcd
n, k = map(int, input().split())
a = list(map(int, input().split()))
if max(a) < k:
    print("IMPOSSIBLE")
    exit()
if k in a:
    print("POSSIBLE")
    exit()
a_gcd = a[0]
for i in range(1, n):
    a_gcd = gcd(a_gcd, a[i])

if k % a_gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

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

h = a[0]
gcda = a[0]

for i in range(1, n):
    if a[i] > h:
        h = a[i]

    gcda = gcd(gcda, a[i])

if k%gcda == 0 and k <= h:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from math import gcd
n,k = map(int,input().split())
A = list(map(int,input().split()))
g = A[0]
m = max(A)
for x in A:
    g = gcd(g,x)
print("POSSIBLE" if k%g == 0 and m >= k else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
N,K=list(map(int,input().split()))
l=list(map(int,input().split()))
import math
if N==1:
   if l[0]==K:
      print("POSSIBLE")
      exit()
   else:
      print("IMPOSSIBLE")
      exit()
A=math.gcd(l[0],l[1])
if K<=max(l):
   for i in range(max(0,N-2)):
      A=math.gcd(A,l[i+2])
   if K%A==0:
      print("POSSIBLE")
   else:
      print("IMPOSSIBLE")
else:
   print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("POSSIBLE") if fl else print("IMPOSSIBLE")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
gcd = math.gcd
n,k = ma()
A = lma()
mx = max(A)
tmp = A[0]
for a in A:
    tmp = gcd(a,tmp)
f=True

if mx<k:
    f=False
    yn(f)
    exit()
if tmp == 1:
    pass
else:
    if k%tmp==0:
        pass
    else:
        f=False
yn(f)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import math
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    gcd = As[0]
    for item in As[1:]:
        gcd = math.gcd(gcd, item)

        
    res = 'IMPOSSIBLE'
    max_A = max(As)
    if max_A > K:
        if K % gcd == 0:
            res = 'POSSIBLE'
    elif K in set(As):
        res = 'POSSIBLE'
    
    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from math import gcd

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

ans=["POSSIBLE","IMPOSSIBLE"]

if max(A)<K:
    print(ans[1])
else:
    g=A[-1]
    for i in range(N-1):
        g=gcd(g,A[i])
    if K%g==0:
        print(ans[0])
    else:
        print(ans[1])

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
n,k=map(int,input().split())
a=list((map(int,input().split())))
b=reduce(gcd,a)
print(['IMPOSSIBLE','POSSIBLE'][k%b==0 and k<=max(a)])

Submission status: Accepted

Solution code:
import sys, bisect, math

N, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))

A.sort()
if bisect.bisect_left(A, K) == N:
    print("IMPOSSIBLE")
    exit()

a = A[0]
for aa in A[1:]:
    a = math.gcd(a, aa)

if K % a != 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, K = mi()
    A = list(mi())

    # Aの最大公約数
    g = A[0]
    for i in range(N):
        g = math.gcd(A[i], g)

    # Aのmax
    m = max(A)
    
    if K%g==0 and m >= K:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

m,k = map(int,input().split())
L = list(map(int,input().split()))

v = reduce(gcd,L)
maxL = max(L)

if k > maxL:
    print("IMPOSSIBLE")
    exit()
if k in L:
    print("POSSIBLE")
    exit()
    
if (maxL - k)%v == 0:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:

import math
from functools import reduce

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


def gcd(*numbers):
    return reduce(math.gcd, numbers)


# 最大公約数を取得
gc = gcd(*A)
max_A = max(A)

if (K % gc == 0 and K <= max_A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
lis.sort()
x=lis[0]
for i in range(n-1):
    x=gcd(x,lis[i+1])
if lis[-1]-k>=0 and (lis[-1]-k)%x==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from sys import exit
from math import gcd

def segfunc(x, y):
    '''
    問題に応じて返り値を設定
    '''
    return gcd(x, y)


def init(a):
    '''
    配列aで初期化
    '''
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def query(p, q):
    '''
    [p, q)についてsegfuncを適用したものを返す
    '''
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


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

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

num = (2 ** len(bin(n - 1)) - 2)
ide_ele = 0
seg = [ide_ele] * 2 * num

init(a)

if k % query(0, n) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')