Given a positive integer n, find k integers (not necessary distinct) such that all these…
- User
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
Output
If it's impossible to find the representation of n as a product of k numbers, print -1.
Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.
Examples
Input
100000 2
Output
2 50000
Input
100000 20
Output
-1
Input
1024 5
Output
2 64 2 2 2
Assistant
def factor(n): factors = [] i = 2 while i * i <= n: while n % i == 0: factors.append(i) n = n // i i += 1 if n > 1: factors.append(n) return factors n, k = map(int, input().split()) if k == 1: print(n) else: factors = factor(n) m = len(factors) if k > m: print(-1) else: if m == k: print(' '.join(map(str, factors))) else: merged = 1 for i in range(m - k + 1): merged *= factors[i] result = [merged] + factors[m - k + 1:] print(' '.join(map(str, result)))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.