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
pythonn, k = map(int, input().split()) if k == 1: print(n) else: if 2 ** k > n: print(-1) else: primes = [] temp = n # Factor out 2s while temp % 2 == 0: primes.append(2) temp //= 2 # Check odd factors i = 3 while i * i <= temp: while temp % i == 0: primes.append(i) temp //= i i += 2 if temp > 1: primes.append(temp) if len(primes) < k: print(-1) else: first_part = primes[:k-1] remaining = primes[k-1:] product_remaining = 1 for num in remaining: product_remaining *= num result = first_part + [product_remaining] 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.