#C2127. Maximize Decomposition

    ID: 45409 Type: Default 1000ms 256MiB

Maximize Decomposition

Maximize Decomposition

You are given two positive integers \(n\) and \(k\). Your task is to decompose \(n\) into \(k\) positive integers \(a_1, a_2, \ldots, a_k\) such that:

\[\sum_{i=1}^{k}a_i = n\]

and the product

[ \prod_{i=1}^{k} a_i ]

is maximized.

The optimal way to achieve this is to distribute \(n\) as evenly as possible among the \(k\) numbers. For instance:

  • Example 1: For \(n=10\) and \(k=2\), the answer is 5 5.
  • Example 2: For \(n=20\) and \(k=3\), a valid answer is 7 7 6.
  • Example 3: For \(n=15\) and \(k=4\), a valid answer is 4 4 4 3.

You need to handle multiple test cases. Read the input from standard input (STDIN) and write the output to standard output (STDOUT).

inputFormat

The first line contains an integer \(T\), representing the number of test cases. Each of the following \(T\) lines contains two space-separated integers \(n\) and \(k\), where \(n\) is the number to be decomposed and \(k\) is the number of parts to divide \(n\) into.

Example:

3
10 2
20 3
15 4

outputFormat

For each test case, output a single line containing \(k\) space-separated integers that represent the optimal decomposition of \(n\) such that their sum is \(n\) and their product is maximized.

Example output corresponding to the above input:

5 5
7 7 6
4 4 4 3
## sample
1
10 2
5 5

</p>