I agree with 340, but this is the way that I approached it,
n=. >: i. 1000 NB. set up list from 1 to 1000
_&q: 1000 NB. returns the prime exponents of 1000
3 0 3
(* _&q:) 1000 NB. returns the prime exponents of 1000^1000
3000 0 3000
(= <.)@:(3 %~ (* _&q:)) 1000 NB. divides the exponents by 3 then returns 1
for integer result
1 1 1
(*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. if all exponents are divisible by
3 then it is a cube
1
+/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. sum up the number of cubes -
returns 1 since 1000^1000 is a cube
1
+/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) n NB. answer for the list up to n^n
340
as it turns out the 340 are these
17 20 $ >: I. *./"1@:(= <.)@:(3 %~ (* _&q:)) n
1 3 6 8 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
57 60 63 64 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111
114 117 120 123 125 126 129 132 135 138 141 144 147 150 153 156 159 162 165 168
171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216 219 222 225 228
231 234 237 240 243 246 249 252 255 258 261 264 267 270 273 276 279 282 285 288
291 294 297 300 303 306 309 312 315 318 321 324 327 330 333 336 339 342 343 345
348 351 354 357 360 363 366 369 372 375 378 381 384 387 390 393 396 399 402 405
408 411 414 417 420 423 426 429 432 435 438 441 444 447 450 453 456 459 462 465
468 471 474 477 480 483 486 489 492 495 498 501 504 507 510 512 513 516 519 522
525 528 531 534 537 540 543 546 549 552 555 558 561 564 567 570 573 576 579 582
585 588 591 594 597 600 603 606 609 612 615 618 621 624 627 630 633 636 639 642
645 648 651 654 657 660 663 666 669 672 675 678 681 684 687 690 693 696 699 702
705 708 711 714 717 720 723 726 729 732 735 738 741 744 747 750 753 756 759 762
765 768 771 774 777 780 783 786 789 792 795 798 801 804 807 810 813 816 819 822
825 828 831 834 837 840 843 846 849 852 855 858 861 864 867 870 873 876 879 882
885 888 891 894 897 900 903 906 909 912 915 918 921 924 927 930 933 936 939 942
945 948 951 954 957 960 963 966 969 972 975 978 981 984 987 990 993 996 999 1000
and the ones that are not multiples of 3 are these
(#~ *@(3&|)) >: I. *./"1@:(= <.)@:(3 %~ (* _&q:)) n
1 8 64 125 343 512 1000
which are the ones that correspond to your (0=1|3%:n)
Cheers, bob
> On Mar 20, 2021, at 23:50, Raul Miller <[email protected]> wrote:
>
> Ah, good point, I should have thought about that. 1 was not the only
> one I needed to concern myself with.
>
> But I think it's this:
>
> +/(0=1|3%:n)+.0=3|n
> 340
>
> I think we can agree that 32^32 isn't a cube
>
> 32^32x
> 1461501637330902918203684832716283019655932542976
>
> 32 is 2^5 and 5*32 is 160, but 160 is not a multiple of 3, so 2^160 is
> not perfect cube,
>
> However,
> (=<.)3%:32^32x
> 1
>
> The problem here is that the cube root of
> 1461501637330902918203684832716283019655932542976 is too large to
> represent the fractional part using floating point.
>
> Still -- good catch.
>
> Thanks,
>
> --
> Raul
>
> On Sun, Mar 21, 2021 at 12:07 AM 'robert therriault' via Programming
> <[email protected]> wrote:
>>
>> Thinking about it a bit further there are many more perfect cubes than that
>> because integers such as 8^8 would not be captured by the %3 rule, but are
>> still perfect cubes.
>>
>> My new answer which is certainly brute force.
>>
>> +/@:(=<.)@:(3&%:) n^n NB. take cube root of each n^n then set each
>> one that is an integer to 1 and then total up the 1's in the list
>> 985
>> 100 timespacex '+/@:(=<.)@:(3&%:) n^n'
>> 5.526e_5 29056
>>
>> Cheers, bob
>>
>>> On Mar 20, 2021, at 20:14, 'robert therriault' via Programming
>>> <[email protected]> wrote:
>>>
>>> Same reasoning as Raul, but quicker and uses less space because we make use
>>> of the structure of n
>>>
>>> (1 + [: <. 3 %~ {:) n
>>> 334
>>> 100 timespacex '1++//0=3 |n'
>>> 2.69e_5 11200
>>> 100 timespacex '(1 +[: <. 3 %~ {:) n'
>>> 5.5e_7 1728
>>>
>>> Cheers, bob
>>>
>>>> On Mar 20, 2021, at 20:01, Raul Miller <[email protected]> wrote:
>>>>
>>>> 1++/0=3 | n
>>>> 334
>>>>
>>>> p is a perfect cube if n is 1 or if n is a multiple of 3.
>>>>
>>>> (1 is the only whole power of 3 which is not a multiple of 3.)
>>>>
>>>> FYI,
>>>>
>>>> --
>>>> Raul
>>>>
>>>> On Sat, Mar 20, 2021 at 10:58 PM Skip Cave <[email protected]> wrote:
>>>>>
>>>>> How do you solve this problem using J (brute force)
>>>>> n =. >: i. 1000
>>>>> p =. n^n
>>>>> How many p are perfect cubes?
>>>>>
>>>>> Skip Cave
>>>>> Cave Consulting LLC
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm