The nth taxicab number, denoted as T(n), is defined as the smallest number that can be expressed as a sum of two positive algebraic cubes in n distinct ways (source: wikipedia).
Example:
T(1) = 2 = 1^3 + 1^3
T(2) = 1729 = 1^3 + 12^3 = 9^3 + 10^3Return the value of n if the given number is a taxicab number. Return 0 if not. If the input is 1729, output would be 2, since 1729 is smallest number that can be expressed as a sum of two cubes in two (n=2) distinct ways.
Avoid look up table solution. Test suit might expand.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers32
Suggested Problems
-
Determine whether a vector is monotonically increasing
22902 Solvers
-
Remove all the words that end with "ain"
2644 Solvers
-
1375 Solvers
-
Sum of first n terms of a harmonic progression
499 Solvers
-
Try 1.5.4: Celsius to Fahrenheit
867 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The solution must be a lookup table since the 6th taxicab number is already greater than 2^64. If anyone find an algorithm for this, DO NOT publish here, publish a scientific paper. Researchers published a paper just about the upper bounds for the 7th to12th number for instance.
The 6th taxicab number is not even a certainty apparently http://jucs.org/jucs_9_10/what_is_the_value/Calude_C_S.pdf
Still, there's a lot that can be done to show that this might be a general solution within MATLAB numeric bounds.
Test cases! E.g. 9 and 4104 would catch when someone isn't checking that they have the SMALLEST number for a given number of ways. (e.g. 9==2^3+1^3, and 4104 == 16^3 + 2^3 == 15^3 + 9^3 are the SECOND smallest numbers for 1 and 2 ways. Random cases could be defined for this one).
Outlaw shortcut functions like str2num. Outlaw the string "1729" and other ways to calculate it and other known taxicab numbers as other than the sum of two cubes two ways. [e.g. it turns out that 1729==prod(1:6:19)].