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>
Here is an idea which should work. It requires a net removal of at most 1 number from the greedy set you construct.
Construct your O(sqrt(M)) list as usual (without result[len - 1] = M - sum;
). If the sum is not a square number (i.e. exact):
Take the difference between your sum now and your target number -> N
Proof:
Examples:
EDIT: error in last case corrected courtesy of @user1952500