#P7947. Construct a Sequence with Given Product and Sum
Construct a Sequence with Given Product and Sum
Construct a Sequence with Given Product and Sum
Given two positive integers n and k, construct a sequence of positive integers \(a_1, a_2, \ldots, a_m\) such that:
\(\prod_{i=1}^{m} a_i = n\) and \(\sum_{i=1}^{m} a_i = k\).
You are allowed to use the number 1 arbitrarily since multiplying by 1 does not change the product. In particular, one strategy is to take the prime factors of n as the base of the sequence; let their sum be \(S\). Then, if \(k \ge S\), you can append \(k-S\) copies of 1 to the sequence so that the overall sum becomes k. If no such sequence exists, output -1.
Note: If n is 1, a valid sequence is simply k copies of 1 (since \(1^k = 1\) and the sum is \(k\)).
inputFormat
The input consists of a single line containing two space-separated positive integers n and k.
outputFormat
If a sequence exists, output the sequence elements separated by a space on a single line. If no valid sequence exists, output -1.
sample
6 5
2 3