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()) primes = [] temp = n i = 2 while i * i <= temp: while temp % i == 0: primes.append(i) temp = temp // i i += 1 if temp > 1: primes.append(temp) if len(primes) < k: print(-1) else: group = primes[:len(primes)-k+1] product = 1 for num in group: product *= num rest = primes[len(primes)-k+1:] result = [product] + rest 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.