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:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

INF = 1 << 50


def run():
    N, K, *A = map(int, read().split())
    A_lists = [A]
    while True:
        generated_A = []
        B = A_lists[-1]
        for i in range(0, len(B), 2):
            if i+1 < len(B):
                val = math.gcd(B[i], B[i+1])
                generated_A.append(val)
            else:
                generated_A.append(B[i])
        A_lists.append(generated_A)
        if len(generated_A) == 1:
            break

    gcd = A_lists[-1][0]
    #print(gcd)
    amax = max(A)
    if not K % gcd and K <= amax:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')



if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    if K > max(A):
        print("IMPOSSIBLE")
        exit()

    x = A[0]

    for i in range(1, N):
        x = math.gcd(A[i], x)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if K > max(A):
    print("IMPOSSIBLE")
    exit()

x = A[0]

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

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

Submission status: Accepted

Solution code:
from math import gcd


def lgcd(x: list):
    res = x[0]
    for i in range(1, len(x)):
        res = gcd(res, x[i])

    return res


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

m = max(a)
g = lgcd(a)

print(["IMPOSSIBLE", "POSSIBLE"][int(k % g == 0 and k <= m)])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[11]:


import math
from functools import reduce


# In[17]:


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


# In[18]:


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


# In[19]:


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


# In[ ]:

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
l = list(map(int,input().split()))
if max(l) < k:
    print("IMPOSSIBLE")
    exit()

x = l[0]
for i in l:
    x = math.gcd(x,i)

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

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
l = list(map(int,input().split()))
if max(l) < k:
    print("IMPOSSIBLE")
    exit()

x = l[0]
for i in l:
    x = math.gcd(x,i)

if x == 1:
    print("POSSIBLE")
else:
    for i in l:
        if (k-i)%x == 0:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
l = sorted(list(map(int,input().split())))
if l[-1] < k:
    print("IMPOSSIBLE")
    exit()
if k in l:
    print("POSSIBLE")
    exit()


x = l[0]
for i in l[1:]:
    x = math.gcd(x,i)

if x == 1:
    print("POSSIBLE")
else:
    for i in l:
        if (k-i)%x == 0:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import math
import functools
n, k = map(int, input().split())
a = list(map(int, input().split()))
a_max = max(a)
G = functools.reduce(math.gcd, a)
ok = True
if k > a_max:
    ok = False
else:
    if k%G == 0:
        pass
    else:
        ok = False

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce
from math import gcd

n, k, *a = map(int, open(0).read().split())
g = reduce(gcd, a)
if k <= max(a) and k%g <1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
from math import gcd

input = sys.stdin.readline


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

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

    if max(A) >= K and K % g == 0:
        ans = "POSSIBLE"
    else:
        ans = "IMPOSSIBLE"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import gcd

n,k = map(int, input().split())
al = list(map(int, input().split()))
a_gcd = al[0]
for a in al[1:]:
    a_gcd = gcd(a_gcd,a)

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
if k > max(a):
    print("IMPOSSIBLE")
else:
    gcd = 0
    for i in range(n):
        gcd = math.gcd(gcd, a[i])
    if k % gcd == 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 a in A:
    G=gcd(G,a)

F=False
for a in A:
    if a>=K and (K-a)%G==0:
        F=True

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

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    n, k = getList()
    nums = getList()
    nums.sort(reverse=True)
    c = nums[0]
    if c < k:
        print("IMPOSSIBLE")
        return
    for num in nums[1:]:
        c = math.gcd(c, num)
    
    if k % c == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")



def main():
    n = getN()
    for _ in range(n):
        solve()

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()

    # 互いに素なペアがあれば、1を作れる
    # 1があればmax(A)以下の数字を作れる
    gcd = A[0]
    for i in A:
        gcd = math.gcd(gcd, i)

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()

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

    from math import gcd

    flag = 0
    if K in A: flag = 1
    elif max(A)<K: flag = 0
    else:
        x = max(A)-K
        g = A.pop(0)
        for a in A:
            g = gcd(g,a)

        if K%g==0:
            flag = 1
        
    print(['IMPOSSIBLE','POSSIBLE'][flag])
    


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

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

num = 0
for ai in a:
    num = gcd(num, ai)
bool = (k % num) or (k > max(a))
print('IMPOSSIBLE' if bool else 'POSSIBLE')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
a = LIST()

if n == 1:
    if a[0] == k:
        print("POSSIBLE")
        exit()
else:
    m = gcd(a[0], a[1])
    for x in a:
        m = gcd(m, x)
    for x in a:
        if x - k >= 0 and ( x - k ) % m == 0:
            print("POSSIBLE")
            exit()
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import math
import functools

n,k = map(int, input().split())
a = list(map(int, input().split()))
g = functools.reduce(math.gcd, a)
if k % g == 0 and k <= max(a):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    A = read_ints()
    if K > max(A):
        return 'IMPOSSIBLE'
    gcd = A[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, A[i])
    if K%gcd != 0:
        return 'IMPOSSIBLE'
    return 'POSSIBLE'


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
from fractions import *
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 k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
n, k, *a = map(int, open(0).read().split())
from functools import*
import math
print("IM" * (k % reduce(math.gcd, a) > 0 or k > max(a)) + "POSSIBLE")

Submission status: Accepted

Solution code:
import math
n,k,*a = map(int,open(0).read().split())
a = list(set(a))
if k in a:
  print("POSSIBLE")
elif k>max(a):
  print("IMPOSSIBLE")
else:
  b = max(a)-k
  c = a.pop()
  for i in a:
    c = math.gcd(c,i)
    if c == 1:
      break
  if b%c == 0:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from functools import reduce

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

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

ans = 'IMPOSSIBLE'  

if max(A) < k:
  pass
else:  
  m = reduce(gcd,A)
  for i in range(n):
    if (k-A[i])%m == 0:
      ans = 'POSSIBLE'
      break
  
print(ans)

Submission status: Accepted

Solution code:
def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def solve():   
    if N == 1:  return A == K    
    g = gcd(A)
    m = max(A)
    return K <= m and K % g == 0

N, K = cin()
A = cin()
ret = solve()
if ret:  print("POSSIBLE")
else:  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd_bl(A):

    left = [0 for _ in range(N + 1)]
    right = [0 for _ in range(N + 1)]
    ans = [0 for _ in range(N)]

    left[1] = A[0]
    for i in range(1, N):  left[i + 1] = gcd_(left[i], A[i])
    right[-1 - 1] = A[-1]
    for i in range(1, N):  right[-1 - i - 1] = gcd_(right[-1 - i], A[-1 - i])
    for i in range(N):  ans[i] = gcd_(left[i], right[i + 1])
        
    return ans

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def solve():   
    if N == 1:  return A == K    
    g = gcd_bl(A)
    for i in range(N):
        if A[i] == K:  return 1
        elif A[i] > K:
            temp = (K - A[i]) / g[i]
            if temp == int(temp):  return 1
    return 0

N, K = cin()
A = cin()
ret = solve()
if ret:  print("POSSIBLE")
else:  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
def main():
    import sys

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

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

    n, k =map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    c = a[0]
    for i in range(n):
        c = gcd(a[i], c)
    if k%c == 0 and k <= a[0]:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd
    from functools import reduce

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

    if a[-1] < k:
        return print("IMPOSSIBLE")

    if n == 1:
        if a[0] == k:
            return print("POSSIBLE")
        else:
            return print("IMPOSSIBLE")
    else:
        g = reduce(gcd, a)
        if k % g == 0:
            return print("POSSIBLE")
        else:
            return print("IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

def cond():
    _max = max(a)
    if k > _max:
        return False
    _gcd = a[0]
    for i in a[1:]:
        _gcd = math.gcd(_gcd, i)
    return (k % _gcd) == 0

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()
if K in A:
    print('POSSIBLE')
    exit()
if K > max(A):
    print('IMPOSSIBLE')
    exit()

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

if K % gc == 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()))
if k in a:
    print("POSSIBLE")
    exit()
tmp = a[0]
for i in range(1,n):
    tmp = math.gcd(tmp,a[i])
for i in a:
    if i > k and (i-k) % tmp == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

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

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def bye(res):
	sT = "IMPOSSIBLE POSSIBLE".split()
	print(sT[res])
	#print(res)
	exit(0)

def main():
	N,K = linput()
	vA = linput(int,set)

	res = 0
	l,r = min(vA), max(vA)
	if K in vA:
		bye(1)
	if not K<=r:
		bye(0)

	g = 0	# GCD for all
	for a in vA:
		g = gcd(g, a)
	print(g, file=sys.stderr)###
	
	if (r-K)%g:
		res = 0
	else:
		res = 1
	bye(res)


if __name__ == "__main__":
	main()

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()))
if k<=max(A) and k%reduce(gcd, A)==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()))

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

Submission status: Accepted

Solution code:
from math import gcd
def main():
  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) and k % g == 0:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a<b:
        a,b = b,a
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b
def gcd_all(A):
    x = A[0]
    if len(A) == 1:
        ret = A[0]
    else:
        for i in range(1,len(A)):
            x = gcd(x,A[i])
        ret = x
    return ret

n,k = map(int,input().split())
a = list(map(int,input().split()))
x = gcd_all(a)
ans = 0
for b in a:
    if b >= k:
        if (b-k)%x == 0:
            ans = 1
            break
print(["IMPOSSIBLE","POSSIBLE"][ans])

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

_, k = map(int, input().split())
ar = list(map(int, input().split()))
mx = max(ar)
m = reduce(gcd, ar)
if k % m == 0 and k <= mx:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

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()))
m=reduce(gcd,a)
if k%m or k>max(a):flag=1
else:flag=0
print(['POSSIBLE','IMPOSSIBLE'][flag])

Submission status: Accepted

Solution code:
import sys
from math import gcd

input = sys.stdin.readline


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

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math


def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    M = max(A)
    g = A[0]
    for a in A[1:]:
        g = math.gcd(g, a)
    if K <= M and K % g == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    if k > max(A):
        print("IMPOSSIBLE")
        exit()

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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import math

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

# 全体のGCDを求める
all_gcd = A[0]
for m in A:
    all_gcd = math.gcd(all_gcd, m)

# Aの最大値より大きい数は作れない
# all_gcdの倍数でない数は作れない
if K <= max(A) and K % all_gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

import math
from functools import reduce

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

g=gcd(*a)
p=max(a)-k
ans='POSSIBLE'
if p>=0:
    if p%g!=0:
        ans='IMPOSSIBLE'
else:
    ans='IMPOSSIBLE'

print(ans)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

import sys
import math
from functools import reduce
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


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


N, K, *A = map(int, read().split())

G = gcd(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
N,K = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
g = A[0]
for i in range(1,N):
    g = gcd(g,A[i])
if K > max(A):
    print("IMPOSSIBLE")
    exit()
if K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b % a, a)


n, k = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
a_gcd = a[0]
for x in a:
    a_gcd = gcd(a_gcd, x)
if k <= max_a and k % a_gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


"""
どれだけ小さい差を作れるかがポイント
maxの値からそれを引くことでいろんな値を作ることができる
もし差が1を作れればmax 以下の値全て作れる
N この最大公約数が最小の差になる
"""

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
if k>max(a):
    ans = 0
elif k in a:
    ans = 1
elif n==1:
    if a[0]==k:
        ans = 1
    else:
        ans = 0
else:
    g = gcd(a[0], a[1])
    for num in a[2:]:
        g = gcd(g, num)
    if k%g==0:
        ans = 1
    else:
        ans = 0
ans = "POSSIBLE" if ans else "IMPOSSIBLE"
print(ans)

Submission status: Accepted

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

# 作れない数字
# ・最大値より大きい数字
# ・GCDの倍数でない数字

if k > a[0]:
    print('IMPOSSIBLE')
    exit()

import math

gcd = a[0]
for i in a:
    gcd = math.gcd(gcd, i)
    if k%gcd == 0:
        print('POSSIBLE')
        exit()
    
print('IMPOSSIBLE')

Submission status: Accepted

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

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

Submission status: Accepted

Solution code:
import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()
    A = in_nl()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

gcd = A[0]

if N == 1:
	if K == A[0]:
		print('POSSIBLE')
		exit()
	else:
		print('IMPOSSIBLE')
		exit()

for i in range (0, N):
	if gcd > 1:
		gcd = math.gcd(gcd, A[i])
	else:
		break
        
if gcd == 1:
	print('POSSIBLE')
elif K%gcd ==0 and K <= max(A):
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from math import gcd
N, K = mapint()
As = list(mapint())

if max(As)<K:
    print('IMPOSSIBLE')
else:
    g = 0
    for a in As:
        g = gcd(g, a)
    else:
        if K%g==0:
            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)

def resolve():
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  if k in a:
    print('POSSIBLE')
    return

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

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

  for x in a:
    if x < k:
      continue
    if (x - k) % g == 0:
      print('POSSIBLE')
      return

  print('IMPOSSIBLE')
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,K = map(int,input().split())
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
flag = 0
for i in range(N):
    if A[i]>=K:
        b = A[i]-K
        if b%a==0:
            flag = 1
            break
if flag==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N,K = I()
A = l()
div = A[0]
if K > max(A):
    print('IMPOSSIBLE')
    exit()
for i in range(1,N):
    div = math.gcd(div,A[i])
if K%div == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')