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 get_prime_factors(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()) primes = get_prime_factors(n) s = len(primes) if s < k: print(-1) else: take = s - k + 1 product = 1 for i in range(take): product *= primes[i] result = [product] + primes[take:] 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.