Odd decomposition of a number

Revision en1, by KiraAvi, 2021-08-28 20:47:33

Let M be an integer in range [1; 1,000,000,000].

A decomposition of M is a set of unique integers whose sum is equal to M.

A decomposition is odd if it contains only odd integers.

A decomposition of M is maximal if there is no other decomposition of M greater in size of the set.

Write a function:

int[] maxOddDecomposition(int M)

that returns an array with a maximal odd decomposition of M. The numbers in array should be in ascending order. If M does not have any odd decomposition, an array should be empty. If there is more than one correct answer, the function may return any of them.

For example, M = 6 has four decompositions:

6 = 1 + 2 + 3 = 1 + 5 = 2 + 4 = 6

Only 1 + 5 is an odd decomposition, thus is the maximal odd decomposition. We should return it in array such that array[0] = 1 and array[1] = 5.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English KiraAvi 2021-08-28 20:47:33 881 Initial revision (published)