Pollock's conjecture
Time limit1sMemory limit128 MB
For each integer below 10^6, find the fewest tetrahedral numbers that sum to it, and the fewest odd tetrahedral numbers that do.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
The -th triangular number is the sum of the first positive integers. The -th tetrahedral number is the sum of the first triangular numbers, and it equals . For example, the 5th tetrahedral number is .
- First 5 triangular numbers:
- First 5 tetrahedral numbers:
In 1850, Sir Frederick Pollock, 1st Baronet — not a professional mathematician, but a British lawyer and politician — conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. A tetrahedral number may appear in the sum more than once, and each occurrence is counted separately. The conjecture has remained open for more than a century and a half.
Write a program that, for each given integer, computes the least number of tetrahedral numbers whose sum equals that integer. In addition, compute the least number of terms when only odd tetrahedral numbers may be used.
For example, 40 can be written as the sum of 2 tetrahedral numbers, (where ), even though 40 itself is not a tetrahedral number. Using only odd tetrahedral numbers, 40 needs at least 6 terms, . So for the input 40 the program reports 2 and 6.
Input
The input consists of several lines, each containing a single positive integer less than . The end of the input is indicated by a line containing a single .
Output
For each input integer, print one line with two integers separated by a single space. The first integer is the least number of tetrahedral numbers whose sum is the given integer. The second integer is the least number of odd tetrahedral numbers whose sum is the given integer. No extra characters should appear in the output.