This question already has an answer here:

I have known this from beginning that $1729$ is the smallest number expressible as the sum of two cubes in two different ways:

$$ 12^3 + 1^3 $$


$$ 10^3+9^3 $$

I am a Software Developer and if someone can tell me the logic to write a program for printing such types of number will be greatly helpful.


marked as duplicate by user147263, Jonas Meyer, Adam Hughes, JimmyK4542, Did Sep 9 '14 at 6:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ I don´t understand what you mean by "next number", other number expressible as the sum of two cubes, or the smallest number greater than 1729 expressible as the sum of two cubes? $\endgroup$ – dwarandae Jan 30 '13 at 15:55
  • 1
    $\begingroup$ oeis.org/A001235 $\endgroup$ – MJD Jan 30 '13 at 17:21
  • $\begingroup$ I am also looking for an efficient program in Pari gp for finding numbers that are sums of three cubes in at least two ways. I do belive that programming efficiency, here, consists in writing first into RAM memory all the numbers which are sum of k cubes (k=2 or (k=3 in my case)) and then just find the numbers that coincide. But i do not know how to write such a program as i am self taught. $\endgroup$ – user55514 Jan 31 '13 at 14:20
  • 1
    $\begingroup$ Note that $1729$ is the smallest number expressible as a sum of two positive integer cubes in two different ways. While allowing a cube of zero doesn't introduce new solutions (case of Fermat's Last Thm.), allowing negative cubes does. For example $9^3 + (-1)^3 = 12^3 + (-10)^3$ is smaller than $1729$. $\endgroup$ – hardmath Jan 31 '13 at 14:36

Check out: Taxi-cab numbers: sums of 2 cubes in more than 1 way

There are a couple of code snippets there for you to work with.

The sequence continues as follows:

$1729 = (1^3 + 12^3)$ or $(9^3 + 10^3)$

$4104 = (2^3 + 16^3)$ or $(9^3 + 15^3)$

$13832 = (2^3 + 24^3)$ or $(18^3 + 20^3)$

$20683 = (10^3 + 27^3)$ or $(19^3 + 24^3)$

$32832 = (4^3 + 32^3)$ or $(18^3 + 30^3)$

$39312 = (2^3 + 34^3)$ or $(15^3 + 33^3)$

$40033 = (9^3 + 34^3)$ or $(16^3 + 33^3)$

$46683 = (3^3 + 36^3)$ or $(27^3 + 30^3)$

$64232 = (17^3 + 39^3)$ or $(26^3 + 36^3)$

$65728 = (12^3 + 40^3)$ or $(31^3 + 33^3)$

After that you have: $110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656$, etc.

You might also be interested in exploring:

$\bullet$ Diophantine Equation--3rd Powers

$\bullet$ Cubic Numbers

$\bullet$ Taxi Numbers in JavaScript


  • $\begingroup$ Almost at a "nice answer" badge...+1 nudge closer ;-) $\endgroup$ – Namaste May 5 '13 at 0:20

This would be essentially solutions to the Diophantine equation, $a^3+b^3=c^3+d^3.$ Which I believe Euler solved for all rational numbers with :$(3a^2+5ab−5b^2)^3+(4a^2−4ab+6b^2)^3+(5a^2−5ab−3b^2)^3 = (6a^2−4ab+4b^2)^3$ This can be rewritten as $(A^2+7AB−9B^2)^3+(2A^2−4AB+12B^2)^3 = (2A^2+10B^2)^3+(A^2−9AB−B^2)^3$ with $a=A+B, b=A-2B.$

The solutions to all integer values only I don't believe has been found, but the solution to some integer values at least has been, and can be found in this paper by Marc Chamberland from 1999: http://www.fq.math.ca/Scanned/38-3/chamberland.pdf

(This is the first answer I posted in this site so I'm not sure if my format for posting is correct, apologies if not)

  • $\begingroup$ That quadratic parameterization does not cover all cases of $a^3+b^3 = c^3+d^3$. $\endgroup$ – Tito Piezas III Jan 16 '18 at 18:07
  • $\begingroup$ Can you give an example that is not covered? $\endgroup$ – Emil Kerimov Jan 19 '18 at 13:10
  • $\begingroup$ The paper you cite gives Euler's formula, but you put Ramanujan's quadratic parameterization instead. There are infinitely many such quadratics, see this post for another example. The complete Euler-Binet formula is this one. $\endgroup$ – Tito Piezas III Jan 19 '18 at 13:53
  • $\begingroup$ You are right, a more general parameterization is in the paper provided in the answer. $\endgroup$ – Emil Kerimov Jan 20 '18 at 19:12

The bruteforce approach is simple.

Loop over integers $k$.

For $1\leq i<\frac k2$ check whether or not $i$ has a cubic root, and whether or not $k-i$ has a cubic root. If so, collect the pair.

When the collection of pairs has more than one pair, collect $k$.

Stop at some arbitrarily large integer, and print the collected $k$'s and the pairs collected for each.

There is probably a much better approach using heuristics though.

  • 1
    $\begingroup$ Slightly less brute force: For $i=1,2,\ldots$ check whether or not $k-i^3$ has a cube root. Stop when $i^3>k/2$. $\endgroup$ – Harald Hanche-Olsen Jan 30 '13 at 15:56
  • $\begingroup$ Of course, in Haskell, you wouldn't need to stop anywhere. You can just calculate them all and print a finite subset. $\endgroup$ – akkkk Jan 30 '13 at 16:03

One logic to generate some taxi-cab numbers is to consider the equation


Now multiply this equation by $k^3$, this gives you $$1729k^3=(11k)^3+(k)^3=(10k)^3+(9k)^3.$$ Now put $k=1,2,3,4,....$ to obtain some terms of this sequence.

  • 2
    $\begingroup$ Do you think I am a fool ?? $\endgroup$ – vikiiii Jan 30 '13 at 16:29
  • 2
    $\begingroup$ @vikiii You simply asked if there was logic to determine taxicab numbers. You didn't ask for an efficient algorithm. The two are very different, and the above approach could be suitable for some purposes. $\endgroup$ – apnorton Jan 30 '13 at 17:27
  • 2
    $\begingroup$ @vikiiii I know it's a pretty naive approach, but brute force( which is the other possible approach) is mentioned in other answers. And therefore I gave such a logic. This method is also used to prove that there exists infinite taxicab numbers. $\endgroup$ – sudeepdino008 Jan 30 '13 at 17:58
  • 1
    $\begingroup$ I am sorry I should not have told you this.Thanks for answering. I should have clearly mentioned that I want an efficent algorithm. $\endgroup$ – vikiiii Jan 31 '13 at 10:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.