2
$\begingroup$

The problem like this: find all integers n, 1 ≤ n ≤ 10, 000 such that n is the sum of two cubes of positive integers in two different ways. I want to solve the problem as a procedure in mathematica.

$\endgroup$

closed as off-topic by Daniel Lichtblau, yarchik, Michael E2, MarcoB, Rolf Mertig Oct 17 at 7:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Daniel Lichtblau, yarchik, Michael E2, MarcoB, Rolf Mertig
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ What have you tried? I would be nice if you post your code even if it is not fully working. By the way, the second number is the taxicab number Ta(2) en.wikipedia.org/wiki/Taxicab_number $\endgroup$ – yarchik Oct 14 at 18:33
  • $\begingroup$ Check FindInstance. $\endgroup$ – corey979 Oct 14 at 18:44
  • $\begingroup$ @yarchik I write a C code first, and I try to translate it into wolfram language, but the console tells me that it has too many recursioni times(over 1000), my C code is like define 8 variables, and use 4 layers for loops to do the calculation, (first layer loop from 1 to 10000, and check the first variable(ac=aaa) greater than 10000 or not, then enter the second layer of for loop, to check bc=bbb, bc+ac>=10000 or not, then until I get all the variables.) the c code working well, but since im a fresh man on mathematica, the wolfram code not working. $\endgroup$ – bajoneet Oct 14 at 19:28
7
$\begingroup$
Clear["Global`*"]

eqns = {n == a^3 + b^3, n == c^3 + d^3, 1 <= n <= 10000, a >= b > 0, 
   a > c >= d > 0};

sol = Solve[eqns, {n, a, b, c, d}, Integers]

(* {{n -> 1729, a -> 12, b -> 1, c -> 10, d -> 9}, {n -> 4104, a -> 16, 
  b -> 2, c -> 15, d -> 9}} *)

And @@ Flatten[eqns /. sol]

(* True *)
$\endgroup$
  • $\begingroup$ Strictly speaking, this does not check there are exactly two solutions, but the smallest number that is the sum of two cubes in three different ways is 87,539,319, so it's safe here. $\endgroup$ – Jean-Claude Arbaut Oct 14 at 18:30
  • $\begingroup$ @Jean-ClaudeArbaut - the OP does not require that the number not be expressible as the sum of three cubes, i.e., it does not say "only two different ways." $\endgroup$ – Bob Hanlon Oct 14 at 18:34
  • $\begingroup$ Interesting. I tend to understand such a sentence as "exactly two". My bad. Anyway, for those interested: mathworld.wolfram.com/TaxicabNumber.html, and of course en.wikipedia.org/wiki/1729_(number) $\endgroup$ – Jean-Claude Arbaut Oct 14 at 18:38
3
$\begingroup$

You could use IntegerPartitions to find integers representable as the sum of two cubes.

Table[
   {n, IntegerPartitions[n, {2}, Range[n]^3]},
   {n, 1, 100}]

Also, PowersRepresentations is designed for problems like this; however, it uses non-negative integers, allowing 0 as one of the cubes.

Table[
   {n, PowersRepresentations[n, 2, 3]},
   {n, 1, 100}]

For "Taxicab Numbers", make a table of representations and select integers with more than one solution. Check that no solution uses 0.

Select[
   Table[
      {n, PowersRepresentations[n, 2, 3]},
      {n, 1, 10000}],
   Length[#[[2]]] >= 2 &]

{{1729, {{1, 12}, {9, 10}}}, {4104, {{2, 16}, {9, 15}}}}

$\endgroup$

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