Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq K \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

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

Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

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

Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

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

Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

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

Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE



Sample input:
3 7
9 3 4


Sample output:
POSSIBLE

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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


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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

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

g = reduce(gcd,A)

x = max(A)
bl = (K <= x) and (K % g == 0)
answer = 'POSSIBLE' if bl else 'IMPOSSIBLE'
print(answer)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import fractions as f
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>max(a):
    print('IMPOSSIBLE')
else:
    if k in a:
        print('POSSIBLE')
    else:
        a.sort()
        cnt=[]
        count=[]
        s=a[0]
        for i in range(n-1):
            cnt.append(f.gcd(a[i],a[i+1]))
        cnt=list(set(cnt))
        ans=0
        for j in range(len(cnt)):
            if k%cnt[j]==0:
                ans=1
        if ans==1:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
n, k = [ int(v) for v in input().split() ]
num = [ int(v) for v in input().split() ]

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

g = gcd(num[0], num[0])
for i in num:
    g = gcd(g, i)

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

Submission status: Accepted

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

def run():
  N, K = map(int, input().split())
  A_li = list(map(int, input().split()))
  if K > max(A_li):
    print('IMPOSSIBLE')
    exit()
  factor = A_li[0]
  for A in A_li[1:]:
    factor = gcd(factor, A)
  if K%factor != 0:
    print('IMPOSSIBLE')
    exit()
  print('POSSIBLE')
  
if __name__ == '__main__':
  run()

Submission status: Accepted

Solution code:
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]

def gcd(ls):
    ls = [i for i in ls if i > 0]
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min
        ls.append(_min)

_gcd = gcd(a_ls)
if max(a_ls) >= k and k % _gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
def gcm(a,b):
  a,b = max(a,b),min(a,b)
  while b != 0:
    a,b = b,a%b
  return a
n,k = map(int,input().split())
a = list(map(int,input().split()))
m = max(a)
g = a[0]
for i in a[1:]:
  g = gcm(g,i)
if m >= k and (m-k)%g == 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Submission status: Accepted

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


if __name__ == "__main__":
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    max_a = max(a)
    while len(a) > 1:
        tmp = gcd(a.pop(), a.pop())
        a.append(tmp)

    if k % a[0] == 0:
        ans = "POSSIBLE"
    else:
        ans = "IMPOSSIBLE"
    if k > max_a:
        ans = "IMPOSSIBLE"
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = 0
for i in range(N):
  if A[i] == K:
    c = 1
if c == 0:
  if K <= max(A):
    for i in range(N-1):
      p, r = A[N-i-2], A[N-i-1]
      while r != 0:
        p, r = r, p % r
      A[N-i-2] = p
      if p == 1:
        break
    if K % p != 0:
      c = -1
    else:
      c = 1
  else:
    c = -1
if c > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import fractions

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

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

if K%g==0 and K<=max(A):
    print('POSSIBLE')
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 =sorted(list(map(int, input().split())))
ans = ''
a = A[0]
for b in range(1, N):
    a = gcd(a, A[b])
if A[N-1] < K:
    ans = 'IMPOSSIBLE'
elif a == 1:
    ans = 'POSSIBLE'
else:
    for n in reversed(A):
        if (n - K) % a == 0:
            ans = 'POSSIBLE'
            break
        else:
            if n < K:
                break
if  ans == '':
    ans = 'IMPOSSIBLE'
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from fractions import gcd
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    m=max(A)
    g=0
    for a in A:
        g=gcd(g,a)

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

Submission status: Accepted

Solution code:
from fractions import gcd
n,k=map(int,input().split())
g=0
m=0
for a in map(int,input().split()):
    g=gcd(g,a)
    m=max(m,a)

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

Submission status: Accepted

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

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

if m < K or (g > 1 and K % g > 0):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

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

Submission status: Accepted

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

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str

def solve(N: int, K: int, A: "List[int]"):
    if K in A:
        print(YES)
        return
    
    if max(A) < K:
        print(NO)
        return
    
    ## 互いに素のものが一つでもあれば1が作れるからなんでも作れる→互いにそのものがあるか判定
    import fractions
    from functools import reduce
    def gcd_list(numbers):
        return reduce(fractions.gcd, numbers)
    
    if gcd_list(A) == 1:
        print(YES)
    else:
        if K%gcd_list(A) == 0:
            print(YES)
        else:
            print(NO)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = max(a)

if k > g:
    print("IMPOSSIBLE")
    exit()

for i in a:
    g = gcd(g, i)

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    while b: a, b = b, a % b
    return a
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
g = reduce(gcd, A)
print("IMPOSSIBLE" if K%g or K > max(A) else "POSSIBLE")

Submission status: Accepted

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

#ボールは消費しない
g = a[0]
for i in range(1,n):
    g = gcd(g,a[i])
    #print(g)

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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

Submission status: Accepted

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

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

def solve() :
    x = A[0]

    for a in A[1:] :
        x = gcd(x, a)
        
    for a in A :
        if a >= K and (a - K) % x == 0 :
            return 'POSSIBLE'
            
    return 'IMPOSSIBLE'
    
print(solve())

Submission status: Accepted

Solution code:
from fractions import gcd


def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num

n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

Submission status: Accepted

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

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

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

if MAX >= K and (MAX-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()))

if n == 1:
    if a[0] == k:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    exit()

m = max(a)

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

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

if k % b == 0 and k <= m:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

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

def main():
    n, q = list(map(int, input().strip().split()))
    v = list(map(int, input().strip().split()))
    v.sort()
    k = v[0]
    for i in range(1, n):
        k = gcd(v[i], k)
    if q <= v[-1] and q % k == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

max_a = max(A)
gcd_num = A[0]
for i in A:
	gcd_num = gcd(gcd_num, i)

if K in A or (K <= max_a and K % gcd_num == 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):
    if a < b:
        a, b = b, a

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

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

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

Submission status: Accepted

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

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


def gcds(*numbers):
    return reduce(gcd, numbers)


if k % gcds(*a) == 0:
    print('POSSIBLE')
    exit(0)
print('IMPOSSIBLE')

Submission status: Accepted

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

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

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

if MAX >= K and (MAX-K)%GCD == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
if k in a:
    print('POSSIBLE')
    quit()
if k > max(a):
    print('IMPOSSIBLE')
    quit()
if 1 in a:
    print('POSSIBLE')
    quit()
a.sort()
tmp = a[1] - a[0]
for i in range(1,n-1):
    tmp = fractions.gcd(a[i+1]-a[i], tmp)
    if tmp == 1:
        break
tmp = fractions.gcd(tmp,a[0])
if tmp == 1 or k%tmp == 0: 
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


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

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

# print(gcd_value)
if K in A:
    print("POSSIBLE")
elif K > max(A):
    print("IMPOSSIBLE")
elif K % gcd_value == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import os
import sys
from fractions import gcd
from functools import reduce

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

g = reduce(gcd, A)
ok = False
for a in A:
    if a == K:
        ok = True
    if a > K:
        ok |= (a - K) % g == 0
if ok:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

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

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
b=gcd(*a)
if max(a)-k>=0 and (max(a)-k)%b==0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import numpy as np
import sys
import math
from functools import reduce
import fractions as fr

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

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

c = int(gcd(*a))

for i in a:
  if i - k >= 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import collections
import fractions
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if K in A:
    print("POSSIBLE")
    exit()
if max(A)<K or len(A)==1:
    print("IMPOSSIBLE")
    exit()
S=collections.Counter([A[i+1]-A[0] for i in range(N-1)])
gcd=S[0]
for s in S:
    gcd=fractions.gcd(gcd,s)


if K%gcd==A[0]%gcd:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Submission status: Accepted

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

Submission status: Accepted

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


def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
# AGC018
import fractions
import functools

def gcd_list(num_list):
    return functools.reduce(fractions.gcd, num_list)

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
if K in A:
    print("POSSIBLE")
    exit()

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

#print(gcd_list(A))
tmp = gcd_list(A)
if tmp == 1 or K % tmp == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))
maxA = max(A)
if K > maxA:
	print("IMPOSSIBLE")
	sys.exit()

if K in A:
	print("POSSIBLE")
	sys.exit()

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

for i in range(1,N):
	if i == 1:
		temp = GCD(A[0],A[1])
	else:
		temp = GCD(temp, A[i])

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

Submission status: Accepted

Solution code:
def main():
    import fractions, functools
    def gcd(li):
        return functools.reduce(fractions.gcd, li)

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def gcd(x, y):
    # x <= y
    x, y = sorted([x, y])
    while x != 0:
        x, y = y%x, x
    return 1 if y == 0 else y
g = a[0]
for i in range(n):
    g = gcd(g, a[i])
if k <= m and k%g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from functools import reduce

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

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

g = reduce(gcd, A)
if K % g == 0:
    flag = True
else:
    flag = False
if max(A) < K:
    flag = False    

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = float("inf")
for i in range(n-1):
  if a[i] == a[i+1]:
    continue
  else:
    c = min(c, a[i+1]-a[i])
    if c == 1:
      break
if k > a[-1]:
  print("IMPOSSIBLE")
else:
  kr = k%c
  for i in a:
    if kr == i%c:
      print("POSSIBLE")
      exit()
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions 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])

    mx = max(a)

    if k > mx:
        bl = False

    else:
        if k % g == 0:
            bl = True
        else:
            bl = False

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from fractions 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])

    mx = max(a)

    if k > mx:
        bl = False

    else:
        if (k - mx) % g == 0:
            bl = True
        else:
            bl = False

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    df = max(a) - k
    return (df >= 0) and (df % g == 0)


if __name__ == '__main__':
    _, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    print('POSSIBLE' if solve(k, a) else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    M = max(A)
    G = reduce(gcd, A)
    if K<=M and K%G==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")   


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def swap(a,b):
    c=a
    a=b
    b=c
    return a,b
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,k = map(int,input().split()) 
    a = list(map(int,input().split()))
    x=a[0]
    for i in range(n-1):
        x=gcd(x,a[i+1])
        if x==1:
            break
    if k in a:
        print("POSSIBLE")
        return
    if x==1 and k<=max(a):
        print("POSSIBLE")
        return
    for i in range(n):
        a[i]-=k
        if a[i]<=0:
            a[i]=-1
        if a[i]%x==0:
            print("POSSIBLE")
            return
    print("IMPOSSIBLE")
main()

Submission status: Accepted

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

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 = A[-1]
for i in A[:-1]:
    g = gcd(g, i)

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def gcdd(*numbers):
    return reduce(gcd, numbers)

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

agcd = gcdd(*a)

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

Submission status: Accepted

Solution code:
import fractions
n,k=map(int,input().split())
l=list(map(int,input().split()))
g=0
for i in l:
    g=fractions.gcd(g,i)
if k%g!=0 or max(l)<k:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Accepted

Solution code:
import fractions
import sys

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

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

A.sort()

if len(A) == 1:
    if A[0] == K:
        print ("POSSIBLE")
    else:
        print ("IMPOSSIBLE")
    sys.exit()

for i in range(N-1):

    if i == 0:
        now = fractions.gcd(A[0],A[1])

    else:
        now = fractions.gcd(now,A[i+1])

if K % now == 0 and K <= A[-1]:
    print ("POSSIBLE")
else:
    print ("IMPOSSIBLE")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
def gcd(n,m):
  if n>m:
    a=n
    b=m
  else:
    a=m
    b=n
  while b!=0:
    a,b=b,a%b
  return a
g=l[0]
max=l[0]
for i in range(1,1+n-1):
  g=gcd(g,l[i])
  if max<l[i]:
    max=l[i]
if max<k:
  print("IMPOSSIBLE")
elif max==k:
  print("POSSIBLE")
else:
  if k%g==0:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

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

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    if k > a[-1]:
        print("IMPOSSIBLE")
    else:
        gcd = 0
        import fractions
        for i in range(n):
            gcd = fractions.gcd(a[i], gcd)
        for i in range(n):
            if a[i] >= k:
                if (a[i] - k) % gcd == 0:
                    print("POSSIBLE")
                    exit()
        print("IMPOSSIBLE")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = min(x,y), max(x,y)
        y %= x
    return x

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

# print(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    if k in w_list:
        return True, w_list
    w_list = sorted(list(set(w_list)))
    ww_list = set([w + K for w in w_list])
    if ww_list & set(w_list):
        return True, w_list
    else:
        return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            # 操作によって作れる差分よりKの方が大きいので
            # これ以上操作してもKを作れない
            break
        if w_list == org_w_list:
            # これ以上操作しても変化がない
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)