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
n, k = map(int, input().split()) def factorize(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 factors = factorize(n) if len(factors) < k: print(-1) else: if k == 1: print(n) else: m = len(factors) - (k - 1) product = 1 for i in range(m): product *= factors[i] result = [product] + factors[m:] 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.