Sum of Cubes
Time limit0.5sMemory limit256 MB
Write N as a sum of as few positive cubes as possible, and among the shortest sums output the one that is lexicographically largest.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
You are given a natural number . Write as a sum of cubes of natural numbers using as few terms as possible. That is, find natural numbers with
where is as small as possible. The same number may be used more than once.
Input
The first and only line contains the natural number ().
Output
Print two lines. The first line contains , the minimum number of cubes. The second line contains natural numbers whose cubes add up to , separated by single spaces and sorted so that no number is smaller than the number after it.
If several sets of numbers work, print the one that comes first in lexicographic order. Compare two sets at the first position where they differ, and the set with the smaller number there comes first. For both and use two cubes, so the answer is 10 9.