
Write all solutions for a^3 + b^3 = c^3 + d^3 - saltcookie
this runs the fastest without memory overhead<p>int Search(){
int MAX = 10000000;
for(int a = 0; a &lt; MAX; a++){
    int a3 = a * a * a;
    if(a3 &gt; MAX) break;
    for(int b = a; b &lt; MAX; b ++){
        int b3 = b * b * b;
        if(a3 + b3 &gt; MAX)break;             
        for(int c = 0; c &lt; a; c++){
            int c3 = c<i>c</i>c;
            int m = a3 - c3; 
            int d = b+1;
            while(true){
                int d3 = d * d * d;
                if(d3-b3 &lt;= m){
                    if((d3 - b3) == m){
                        count++;
                        PUSH_SOLUTION(a3, b3, c3, b3, a, b, c, d);
                    }
                    d++;
                    continue;
                }
                else
                    break;
            }
        }
    }
}
return 0;
}
======
dalke
As one of the comments points out, these are the so-called "taxicab numbers",
based on a story about Hardy trying to make small talk with Ramanujan. Hardy's
taxicab's number was 1729, which he found boring. Ramanujan pointed out it was
the first number which was the sum of two different cubes in two different
ways.

There are six known taxicab numbers; see
[http://en.wikipedia.org/wiki/Taxicab_number](http://en.wikipedia.org/wiki/Taxicab_number)
for a list and their decompositions. The solutions at
[http://math.stackexchange.com/questions/2815/find-taxicab-
nu...](http://math.stackexchange.com/questions/2815/find-taxicab-numbers-in-
on-time) are much more knowledgeable about math than the ones at
StackOverflow, as one might expect.

Note that in your/saltcookie's proposed answer there is mistranslation of the
problem. The posed question says "a, b, c, d lie between [0, 10^5]" but does
not restrict their cubes, while you have a test for "if(a3 > MAX)" and "if(a3
+ b3 > MAX)".

Even if those checks are removed, there is still a likely overflow error
because most systems use 32 bit integers for 'int'. a * a * a as an int may be
a number <= 10000000, including a negative number.

That is, your output should include 48988659276962496 = 38787^3 + 365757^3 as
an answer because 38787 < 365757 < 10000000 so fits the input constraints;
note that 48988659276962496 cannot be represented as a 32 bit integer.

------
saltcookie
[http://stackoverflow.com/a/20901679/924801](http://stackoverflow.com/a/20901679/924801)

