#P1887. Maximum Product Partition with Lexicographical Order

    ID: 15170 Type: Default 1000ms 256MiB

Maximum Product Partition with Lexicographical Order

Maximum Product Partition with Lexicographical Order

Given two positive integers M and N, you are required to find M positive integers whose sum is N such that their product is maximized. Among all possible solutions that yield the maximum product, output the lexicographically smallest sequence.

It is well known that to maximize the product for a given sum, the numbers should be as equal as possible. Let \(x = \lfloor \frac{N}{M} \rfloor\) and \(r = N \bmod M\). Then the optimal solution is to choose \(M-r\) copies of \(x\) and \(r\) copies of \(x+1\). To ensure the sequence is lexicographically smallest, output the numbers in non-decreasing order, i.e., first all \(x\)'s then all \(x+1\)'s.

Note: All numbers are positive integers.

inputFormat

The input consists of a single line containing two space-separated integers M and N (M > 0, N >= M).

outputFormat

Output a single line containing M space-separated positive integers representing the lexicographically smallest sequence that maximizes the product, as described above.

sample

3 8
2 3 3

</p>