Блог пользователя KiraAvi

Автор KiraAvi, история, 5 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится