How to resolve the algorithm Aliquot sequence classifications step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Aliquot sequence classifications step by step in the J programming language
Table of Contents
Problem Statement
An aliquot sequence of a positive integer K is defined recursively as the first member being K and subsequent members being the sum of the Proper divisors of the previous term.
Show all output on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Aliquot sequence classifications step by step in the J programming language
Source code in the j programming language
proper_divisors=: [: */@>@}:@,@{ [: (^ i.@>:)&.>/ 2 p: x:
aliquot=: +/@proper_divisors ::0:
rc_aliquot_sequence=: aliquot^:(i.16)&>
rc_classify=: 3 :0
if. 16 ~:# y do. ' invalid '
elseif. 6 > {: y do. ' terminate '
elseif. (+./y>2^47) +. 16 = #~.y do. ' non-terminating'
elseif. 1=#~. y do. ' perfect '
elseif. 8= st=. {.#/.~ y do. ' amicable '
elseif. 1 < st do. ' sociable '
elseif. =/_2{. y do. ' aspiring '
elseif. 1 do. ' cyclic '
end.
)
rc_display_aliquot_sequence=: (rc_classify,' ',":)@:rc_aliquot_sequence
rc_display_aliquot_sequence&> >: i.10
terminate 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 4 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
perfect 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
terminate 7 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 8 7 1 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 9 4 3 1 0 0 0 0 0 0 0 0 0 0 0 0
terminate 10 8 7 1 0 0 0 0 0 0 0 0 0 0 0 0
rc_display_aliquot_sequence&>11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080x
terminate 11 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 12 16 15 9 4 3 1 0 0 0 0 0 0 0 0 0
perfect 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
perfect 496 496 496 496 496 496 496 496 496 496 496 496 496 496 496 496
amicable 220 284 220 284 220 284 220 284 220 284 220 284 220 284 220 284
amicable 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210
sociable 12496 14288 15472 14536 14264 12496 14288 15472 14536 14264 12496 14288 15472 14536 14264 12496
sociable 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184
aspiring 790 650 652 496 496 496 496 496 496 496 496 496 496 496 496 496
aspiring 909 417 143 25 6 6 6 6 6 6 6 6 6 6 6 6
cyclic 562 284 220 284 220 284 220 284 220 284 220 284 220 284 220 284
cyclic 1064 1336 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210
non-terminating 1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384
non-terminating 15355717786080 44534663601120 144940087464480 471714103310688 1130798979186912 2688948041357088 6050151708497568 13613157922639968 35513546724070632 74727605255142168 162658586225561832 353930992506879768 642678347124409032 1125102611548462968 1977286128289819992 3415126495450394808
You may also check:How to resolve the algorithm Polynomial long division step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the newLISP programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Action! programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the BASIC programming language
You may also check:How to resolve the algorithm Decorate-sort-undecorate idiom step by step in the Perl programming language