This is not a duplicate of this question. This is asking for the nth number that can be represented as the sum of two cubes in two different ways, while that is asking for the n-th number that can be expressed as the sum of two cubes in n ways.


I was just watching The man who knew Infinity, and I thought it would make a good challenge.

So, what's the challenge??

You must write a program that will calculate the n-th number that can be expressed as the sum of two cubes, not in one way, but exactly two.


  • You may output either the n-th number, or an array up to (and including) the n-th value.
  • You must output both sums of cubes (however you'd like), and the number, for each output.
  • You cannot hardcode any solutions.
  • Runtime will be my Arch Linux laptop with 16 GB of RAM and an Intel i7 processor.
  • Negitive numbers are not used.


  • The winner is the solution who's runtime for n = 10 (in seconds) times the code size is smallest.
  • 1
    \$\begingroup\$ @orlp That is asking for the "n-th number that can be expressed as the sum of 2 cubes in n ways", not 2. This is different, albeit similar. \$\endgroup\$ May 27, 2016 at 2:51
  • \$\begingroup\$ @orlp "are the least numbers that are able to be represented as n different sums of two positive cubed integers, for successive n." (Bold added by me) \$\endgroup\$ May 27, 2016 at 2:52
  • \$\begingroup\$ Does it have to be exactly two ways and no more, or at least two ways? What about negative numbers? \$\endgroup\$
    – orlp
    May 27, 2016 at 2:54
  • \$\begingroup\$ Given your intro paragraph, shouldn't "but exactly two" be "but exactly n"? \$\endgroup\$ May 27, 2016 at 3:00
  • \$\begingroup\$ Different people have different computers and runtime will vary. Speed can even depend on the number of background processes, making it unreliable as a metric. \$\endgroup\$
    – Zwei
    May 27, 2016 at 3:00