Skip to main content
added 350 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
SeedRandom[1] 
While[Length[pr] < 2, 
  pr = Select[FreeQ @ 0] @ PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; //
     AbsoluteTiming // First
5.8*10^-6
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}

If you want the 6 numbers all distinct:

SeedRandom[1]
While[Length[Union @@ pr] < 6, 
    pr = Select[FreeQ@0]@
      PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; // 
  AbsoluteTiming // First
 0.0000275
pr
 {{5, 53, 88}, {12, 29, 93}, {15, 74, 75}}
Total[pr[[1]]^3]
830474
SeedRandom[1] 
While[Length[pr] < 2, 
  pr = Select[FreeQ @ 0] @ PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; //
     AbsoluteTiming // First
5.8*10^-6
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
SeedRandom[1] 
While[Length[pr] < 2, 
  pr = Select[FreeQ @ 0] @ PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; //
     AbsoluteTiming // First
5.8*10^-6
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}

If you want the 6 numbers all distinct:

SeedRandom[1]
While[Length[Union @@ pr] < 6, 
    pr = Select[FreeQ@0]@
      PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; // 
  AbsoluteTiming // First
 0.0000275
pr
 {{5, 53, 88}, {12, 29, 93}, {15, 74, 75}}
Total[pr[[1]]^3]
830474
added 4 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
SeedRandom[1] 
While[Length[prWhile[Length[pr] < 2, 
  pr = Select[FreeQ @ 0] @
   PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]] < 2];3]]; //
     AbsoluteTiming // First
05.00090088*10^-6
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
SeedRandom[1] 
While[Length[pr = Select[FreeQ @ 0] @
   PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]] < 2]; //
     AbsoluteTiming // First
0.0009008
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
SeedRandom[1] 
While[Length[pr] < 2, 
  pr = Select[FreeQ @ 0] @ PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]]; //
     AbsoluteTiming // First
5.8*10^-6
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
added 127 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
SeedRandom[1] 
While[Length[pr = Select[FreeQ @ 0] @
   PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]] < 2]; //
pr     AbsoluteTiming // First
0.0009008
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
SeedRandom[1] 
While[Length[pr = Select[FreeQ @ 0] @
   PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]] < 2]; 
pr
{{2, 3, 16}, {3, 9, 15}}
Total[pr^3, {2}]
{4131, 4131}
SeedRandom[1] 
While[Length[pr = Select[FreeQ @ 0] @
   PowersRepresentations[RandomInteger[{2, 10^6}], 3, 3]] < 2]; //
     AbsoluteTiming // First
0.0009008
 {{a, b, c}, {d, k, f}, n} = Join[pr[[;;2]], {Total[pr[[1]]^3]}]
{{2, 3, 16}, {3, 9, 15}, 4131}
Total[pr^3, {2}]
{4131, 4131}
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading