Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def readArray():
- return tuple(map(int, input().split()))
- _, m, k = readArray()
- a = readArray()
- dedup = set(a)
- indices = {}
- for i in dedup:
- indices[i] = list(
- map(
- lambda x: x[0],
- filter(
- lambda x: x[1] == i,
- enumerate(a)
- )
- )
- )
- def step(n, depth, current):
- candidates = tuple(
- filter(
- lambda x: n % x == 0,
- dedup
- )
- )
- if depth == k:
- try:
- x = tuple(
- filter(
- lambda i: n == i, candidates
- )
- )[0]
- except IndexError:
- return None
- else:
- return [*current, x]
- for i in candidates:
- x = step(n // i, depth + 1, [*current, i])
- if x == None:
- continue
- else:
- return x
- return None
- print([1 + indices[i].pop() for i in step(m, 1, [])])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement