Sum of Two Cubes
You are given an integer n.
A positive integer x is called special if there exist at least two distinct pairs of positive integers (a, b) such that:
- a <= b
- x = a3 + b3
Return an array containing all such special integers in the range [1, n], sorted in ascending order.
Two pairs are considered distinct if their values of (a, b) are different.
Example 1:
Input: n = 2000
Output: [1729]
Explanation:
1729 is special because it can be written in two different ways:
- 13 + 123 = 1729
- 93 + 103 = 1729
No other integer less than or equal to 2000 satisfies the condition.
Example 2:
Input: n = 5000
Output: [1729, 4104]
Explanation:
- 1729 = 13 + 123 = 93 + 103
- 4104 = 23 + 163 = 93 + 153
Both have at least two distinct valid pairs.
Now Your Turn!
Pick the correct output for the given inputInput: n = 5000
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 109
- a and b are positive integers
- Only pairs satisfying a <= b are considered valid
- The answer must be returned in ascending order