Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def readArray():
  2.   return tuple(map(int, input().split()))
  3.  
  4. _, m, k = readArray()
  5. a = readArray()
  6. dedup = set(a)
  7.  
  8. def step(n, depth, current):
  9.   candidates = tuple(filter(lambda x: n % x == 0, dedup))
  10.  
  11.   if depth == k:
  12.     try:
  13.       x = tuple(filter(lambda i: n == i, candidates))[0]
  14.     except IndexError:
  15.       return None
  16.     else:
  17.       return [*current, x]
  18.  
  19.   for i in candidates:
  20.     x = step(n // i, depth + 1, [*current, i])
  21.     if x == None:
  22.       continue
  23.     else:
  24.       return x
  25.  
  26.   return None
  27.  
  28. print([1 + a.index(i) for i in step(m, 1, [])])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement