Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 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. indices = {}
  9.  
  10. for i in dedup:
  11.   indices[i] = list(
  12.     map(
  13.       lambda x: x[0],
  14.       filter(
  15.         lambda x: x[1] == i,
  16.         enumerate(a)
  17.       )
  18.     )
  19.   )
  20.  
  21. def step(n, depth, current):
  22.   candidates = tuple(
  23.     filter(
  24.       lambda x: n % x == 0,
  25.       dedup
  26.     )
  27.   )
  28.  
  29.   if depth == k:
  30.     try:
  31.       x = tuple(
  32.         filter(
  33.           lambda i: n == i, candidates
  34.         )
  35.       )[0]
  36.     except IndexError:
  37.       return None
  38.     else:
  39.       return [*current, x]
  40.  
  41.   for i in candidates:
  42.     x = step(n // i, depth + 1, [*current, i])
  43.     if x == None:
  44.       continue
  45.     else:
  46.       return x
  47.  
  48.   return None
  49.  
  50. print([1 + indices[i].pop() for i in step(m, 1, [])])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement