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:
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
import fractions
num = a[0]
for i in range(1, n):
    num = fractions.gcd(num, a[i])

if k > a[-1]:
    print("IMPOSSIBLE")
elif (k in a) or (k%num==0):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

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

mm = A[0]

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

for i in range(N):
    if A[i]-K>=0 and (A[i]-K)%mm==0:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions

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

g = A[-1]
for a in A:
    g = fractions.gcd(a, g)

if k % g == 0 and k <= A[-1]:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

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

import math
import fractions
flag=True
#最大公約数
def union_gcd(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=fractions.gcd(num,lists[i])
        return num
if k%union_gcd(lists)==0 and k<=max(lists):
    flag=True
else:
    flag=False
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

import fractions
ans=A[0]
for i in range(1,N):
  ans=fractions.gcd(ans,A[i])
if K>a:
  print('IMPOSSIBLE')
  exit()
if (a-K)%ans==0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
A = [int(x) for x in input().strip().split()]

if K > max(A):
    print('IMPOSSIBLE')
    exit()
if K in A:
    print('POSSIBLE')
    exit()

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

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

if K % gcd_ == 0:
    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

if n == 1:
    gcd1 = a[0]
else:
    gcd1 = gcd(a[0], a[1])

    for i in range(2,n):
        gcd1 = gcd(gcd1,a[i])

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

Submission status: Accepted

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

a = [0] + a
a.sort()
if max(a) < k:
    print("IMPOSSIBLE")
    exit()

for i in range(len(a) - 1):
    if k == a[i]:
        print("POSSIBLE")
        break
    if a[i+1] - a[i] == 0: continue 
    if k % (a[i+1] - a[i]) == 0:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

GCD = gcd_list(A)

if K > A[0]:
  print("IMPOSSIBLE")
elif K % GCD != 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N,K,*A=map(int, open(0).read().split())
g=reduce(gcd, A)
if (g==gcd(g,K) or K in A) and K<=max(A):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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()))

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

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

input=sys.stdin.readline

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

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

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

Submission status: Accepted

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

from functools import reduce
from fractions import gcd

g = reduce(gcd, a)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# GCD
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

# lのGCD
def gcdlist(l):
    res = l[0]
    for i in range(1,len(l)):
        res = gcd(res, l[i])
    return res


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

m = gcdlist(al)
al.sort(reverse=True)

for a in al:
    if a>k:
        if (a-k)%m==0:
            print("POSSIBLE")
            exit()
    elif a==k:
        print("POSSIBLE")
        exit()
    else:
        break
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
from functools import reduce
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#agc018 getting difference
n,k=mii()
arr=limii()
#print(arr)
def gcd1(numbers):
    return reduce(gcd,numbers)

p=gcd1(arr)

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

Submission status: Accepted

Solution code:
# coding: utf-8
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
a = 0
for i in range(N):
    a = gcd(a, A[i])
if K % a == 0 and K <= A[-1]:
    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 a in A[1:]:
    g = fractions.gcd(g, a)

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd(l):
    return reduce(fractions.gcd, l)
    
n, k = map(int, input().split())
a = list(map(int, input().split()))

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

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 = [ int(x) for x in input().split() ]

g = 0
for aa in a:
    g = gcd(g, aa)

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

ans = 'IMPOSSIBLE'

if max(A) < M:
    print(ans)
elif M in A:
    ans = 'POSSIBLE'
    print(ans)
else:
    g = A[-1]
    for a in A:
        g = gcd(g, a)
    if M % g == 0:
        ans = 'POSSIBLE'
        print(ans)
    else:
        print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    g = A[0]
    for i in range(1, N):
        g = Math.gcd(g, A[i])
    if K % g == 0 and max(A) >= K:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k%reduce(gcd,a)==0 and max(a)>=k:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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()
gcd = li[0] 
for i in range(n-1):
    gcd = fractions.gcd(gcd,li[i+1])
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")

Submission status: Accepted

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

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

tmp = al[0]
for a in al:
    tmp = gcd(a, tmp)

if k % tmp == 0 and max(al) >= k:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

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

A.sort()
if A[-1] < K:
    print("IMPOSSIBLE")
    sys.exit()
    
s = A[0]
for i in A:
    s = gcd(s, i)

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(A):
    if len(A) == 1:
        return A[0]
    else:
        return reduce(gcd,A)

N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = gcdlist(A)
if (K in A or (K%ans == 0)) and K <= max(A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

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

if k > lst[-1]:
    print('IMPOSSIBLE')
elif k in lst:
    print('POSSIBLE')
else:
    dif = 10**5
    a = lst[0]
    b = lst[1]
    
    while True:
        dif = b-a
        if dif in lst or dif <= 0:
            break
        else:
            lst.append(dif)
            b = max(dif, a)
            a = min(dif, a)
    
    mn = min(lst)
    for l in lst:
        if l>k and (l-k)%mn==0:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor:GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple:LCM)を求める
    計算量: O(log(min(a, b)))"""
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める
    計算量: O(Nlog)
    """
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


def multi_lcm(array: list) -> int:
    """arrayのLCMを求める"""
    ans = array[0]
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
    return ans

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

gcd_ = multi_gcd(a)
max_a = max(a)
if max_a < k:
    print("IMPOSSIBLE")
elif 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()))

# print(N, K, A)

ma = 0
d = A[0]
found = False
for a in A:
    ma = max(ma, a)
    d = gcd(d, a)
    if a == K:
        found = True
if found:
    print('POSSIBLE')
    exit()

if ma < K:
    print('IMPOSSIBLE')
    exit()
if K % d == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

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

import fractions as math
#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = math.gcd(a,l[i])
        if a == 1:
            break
    return a


p = gcdlist(lst1)

if max(lst1) < k:
    print("IMPOSSIBLE")

elif k in lst1:
    print("POSSIBLE")

elif k%p==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions
length, target = map(int, input().split(" "))
nums = sorted([int(n) for n in input().split(" ")])
minimum = min(nums)
odd, even, gcd = 0, 0, minimum
for n in nums:
    if n % 2 == 0:
        even = 1
    else:
        odd = 1
    gcd = fractions.gcd(gcd, n)
if target > max(nums):
    print("IMPOSSIBLE")
elif target in nums:
    print("POSSIBLE")
else:
    if gcd == 1:
        print("POSSIBLE")
    else:
        if target % gcd == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

@mt
def slv(N, K, A):
    from fractions import gcd
    G = reduce(gcd, A)
    if K <= max(A) and K % G == 0:
        return 'POSSIBLE'
    else:
        return 'IMPOSSIBLE'

def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
import functools

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
maximum = max(A)
lcm = functools.reduce(lambda a, b: fractions.gcd(a, b), A)
if K % lcm == 0 and K <= maximum:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
print(ans)

Submission status: Accepted

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

def gcdlist(l):
    a = l[0]
    for i in range(1,len(l)):
        a = gcd(a,l[i])
    return a

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

g = gcdlist(A)
M = max(A)
if K > M:
    ans = 'IMPOSSIBLE'
elif K%g == 0:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'

print(ans)

Submission status: Accepted

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

def gcdlist(l):
    a = l[0]
    for i in range(1,len(l)):
        a = gcd(a,l[i])
    return a

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

g = gcdlist(A)
M = max(A)
if K > M:
    ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K%g == 0:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'

print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

if N == 1:
    if A[0] == K:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    G = A[0]
    for i in range(1,N):
        G = fractions.gcd(A[i],G)
    if K <= M and K % G == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
def gcds(a):
  return reduce(gcd, a)

n,k = map(int,input().split())
a = list(map(int,input().split()))
if k%gcds(a) == 0 and max(a)>=k:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=set(map(int,input().split()))
NO='IMPOSSIBLE'
YES='POSSIBLE'

max_A=max(A)
if K>max_A:
    print(NO)
    exit()

if K in A:
    print(YES)
    exit()

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

GCD=0
for n in A:
    GCD=gcd(GCD,n)

if GCD==1 or K%GCD==0:
    print(YES)
else:
    print(NO)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, K, = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

if max(L) < K:
    print("IMPOSSIBLE")
    exit()

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

p = L[0]
for v in L:
    p = gcd(p, v)

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

Submission status: Accepted

Solution code:
#coding:utf-8
#import math
import fractions
from functools import reduce
n,k = map(int, input().split())
A = list(map(int, input().split()))
gcd = reduce(fractions.gcd, A)
if (min(A)<=k and k<=max(A) and 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()))
g = 0

for i in range(N):
    g = gcd(a[i], g)
amax = max(a)
q, mod = divmod(K, g)

if mod != 0 or amax < K:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
N, K = map(int, input().split())
a = list(map(int, input().split()))
g = 0

for i in range(N):
    g = gcd(a[i], g)
amax = max(a)
q, mod = divmod(K, g)

if mod != 0 or amax < K:
    print('IMPOSSIBLE')
else:
    if q <= amax:
        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()
mx = a[-1]
if mx < k:
    ans = 'IMPOSSIBLE'
elif n == 1:
    if a[0] == k:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
else:
    gcd = fractions.gcd(a[0],a[1])
    for i in range(0,n):
        gcd = fractions.gcd(gcd,a[i])
    if k % gcd == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
print(ans)

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()))
amax = max(A)
if K>amax:
    print("IMPOSSIBLE")
else:
    a = A[0]
    for i in range(1,N):
        a = gcd(a,A[i])
    if (amax-K)%a == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
#solve
def solve():
    n, k = LI()
    a = LI()
    if k in a:
        print("POSSIBLE")
        return
    if max(a) < k:
        print("IMPOSSIBLE")
        return
    g = a[0]
    for ai in a:
        g = gcd(g, ai)
    if k % g != 0:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=float('inf')
if k>max(a):
  print('IMPOSSIBLE')
else:
  for i in range(n):
    b=min(gcd(a[0],a[i]),b)
  if k%b==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()))
gcdA = reduce(gcd,A)
print('POSSIBLE' if K%gcdA ==0 and K<=max(A) else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline

import fractions

N,K=two_int()

A=many_int()

if K <= max(A):
    temp=A[0]
    for a in A[1:]:
        temp = fractions.gcd(temp,a)

    if fractions.gcd(temp,K)!=1 or temp==1:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE") 

else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n,k= map(int,input().split())
a = list(map(int,input().split()))
if k in a:
  print('POSSIBLE')
  exit()
elif k > max(a):
  print('IMPOSSIBLE')
  exit()
    
m = reduce(gcd, a)
for i in a:
  if (i - k) % m == 0:
    print('POSSIBLE')
    break
else:
  print('IMPOSSIBLE')

Submission status: Accepted

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

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

Submission status: Accepted

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

if(k in a):
	print("POSSIBLE")
	sys.exit()

maxa=max(a)
mindiff=a[0]
for i in range(len(a)-1):
	mindiff=fractions.gcd(mindiff,a[i])

a_more_k=[a[i] for i in range(len(a)) if a[i]>k]
for i in range(len(a_more_k)):
	if( (a_more_k[i]-k)%mindiff == 0):
		print("POSSIBLE")
		sys.exit()

print("IMPOSSIBLE")

Submission status: Accepted

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

diffs=[]
for i in range(len(A)):
  if A[i]>=K:
    diffs.append(A[i]-K)
    
def gcd(a,b):
  if a>b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b

g=A[0]
for i in range(1,len(A)):
  g=gcd(g,A[i])
  
for dif in diffs:
  if dif%g==0:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

Submission status: Accepted

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

diffs=[]
for i in range(len(A)):
  if A[i]>K:
    diffs.append(A[i]-K)
    
def gcd(a,b):
  if a>b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b

g=A[0]
for i in range(1,len(A)):
  g=gcd(g,A[i])
  
for dif in diffs:
  if dif%g==0:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd


def greatest_common_divisor(iter):
    '''
    最大公約数を返す
    '''
    return reduce(gcd, iter)


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

if K % greatest_common_divisor(A) != 0 or K > max(A):
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Accepted

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

ans = 'IMPOSSIBLE'
if max(A) >= K:
    # from math import gcd
    from fractions import gcd
    from functools import reduce
    g = reduce(gcd,A)
    # print(g)
    if K % g == 0: ans = 'POSSIBLE'

print(ans)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
def examA():
    N, K = LI()
    A = LI()
    ans = "POSSIBLE"
    if max(A)<K:
        ans = "IMPOSSIBLE"
    cur = A[0]
    for i in range(1,N):
        cur = gcd(cur,A[i])
    if K%cur!=0:
        ans = "IMPOSSIBLE"
    print(ans)
    return

def examB():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examA()

Submission status: Accepted

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

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

A.sort()

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

if K in A or 1 in A:
    print("POSSIBLE")
    exit()

def gcd(a,b):
    x = max([a,b])
    y = min([a,b])
    while y:
        x, y = y, x % y
    return x

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
new_balls = []
a.sort()
if k > a[-1]:
    print('IMPOSSIBLE')
    exit()
if k in a:
    print('POSSIBLE')
    exit()
for i in range(1, n):
    diff = a[i] - a[i - 1]
    if diff > 0:
        new_balls.append(diff)
for nb in new_balls:
    if (a[-1] - k) % nb == 0:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def gcd(l, r):
  while r > 0:
    l, r = r, l % r
  return l

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

if __name__ == '__main__':
  main()