user
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.

:   * If the terms eventually reach 0 then the series for K is said to **terminate**.

:   There are several classifications for non termination:

    * If the second term is K then all future terms are also K and so the sequence repeats from the first term with period 1 and K is called **perfect**.
    * If the third term *would* be repeating K then the sequence repeats with period 2 and K is called **amicable**.
    * If the Nth term *would* be repeating K for the first time, with N > 3 then the sequence repeats with period N - 1 and K is called **sociable**.
:   Perfect, amicable and sociable numbers eventually repeat the original number K; there are other repetitions...

    * Some K have a sequence that eventually forms a periodic repetition of period 1 but of a number other than K, for example 95 which forms the sequence `95, 25, 6, 6, 6, ...` such K are called **aspiring**.
    * K that have a sequence that eventually forms a periodic repetition of period >= 2 but of a number other than K, for example 562 which forms the sequence `562, 284, 220, 284, 220, ...` such K are called **cyclic**.

:   And finally:

    * Some K form aliquot sequences that are not known to be either terminating or periodic; these K are to be called **non-terminating**.   
      For the purposes of this task, K is to be classed as non-terminating if it has not been otherwise classed after generating **16** terms or if any term of the sequence is greater than 2\*\*47 = 140,737,488,355,328.

Task

1. Create routine(s) to generate the aliquot sequence of a positive integer enough to classify it according to the classifications given above.
2. Use it to display the classification and sequences of the numbers one to ten inclusive.
3. Use it to show the classification and sequences of the following integers, in order:

:   :   11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, and optionally 15355717786080.

Show all output on this page.

Related tasks

* Abundant, deficient and perfect number classifications. (Classifications from only the first two members of the whole sequence).
* Proper divisors
* Amicable pairs

External links

* An amazing thing about 276, Numberphile
assistant
(formerly Perl 6)

**Works with**: rakudo version 2018.10

```
sub propdivsum (\x) {
    my @l = x > 1;
    (2 .. x.sqrt.floor).map: -> \d {
        unless x % d { my \y = x div d; y == d ?? @l.push: d !! @l.append: d,y }
    }
    sum @l;
}

multi quality (0,1)  { 'perfect ' }
multi quality (0,2)  { 'amicable' }
multi quality (0,$n) { "sociable-$n" }
multi quality ($,1)  { 'aspiring' }
multi quality ($,$n) { "cyclic-$n" }

sub aliquotidian ($x) {
    my %seen;
    my @seq = $x, &propdivsum ... *;
    for 0..16 -> $to {
        my $this = @seq[$to] or return "$x\tterminating\t[@seq[^$to]]";
        last if $this > 140737488355328;
        if %seen{$this}:exists {
            my $from = %seen{$this};
            return "$x\t&quality($from, $to-$from)\t[@seq[^$to]]";
        }
        %seen{$this} = $to;
    }
    "$x non-terminating\t[{@seq}]";
}

aliquotidian($_).say for flat
    1..10,
    11, 12, 28, 496, 220, 1184, 12496, 1264460,
    790, 909, 562, 1064, 1488,
    15355717786080;

```

Output:

```
1	terminating	[1]
2	terminating	[2 1]
3	terminating	[3 1]
4	terminating	[4 3 1]
5	terminating	[5 1]
6	perfect 	[6]
7	terminating	[7 1]
8	terminating	[8 7 1]
9	terminating	[9 4 3 1]
10	terminating	[10 8 7 1]
11	terminating	[11 1]
12	terminating	[12 16 15 9 4 3 1]
28	perfect 	[28]
496	perfect 	[496]
220	amicable	[220 284]
1184	amicable	[1184 1210]
12496	sociable-5	[12496 14288 15472 14536 14264]
1264460	sociable-4	[1264460 1547860 1727636 1305184]
790	aspiring	[790 650 652 496]
909	aspiring	[909 417 143 25 6]
562	cyclic-2	[562 284 220]
1064	cyclic-2	[1064 1336 1184 1210]
1488 non-terminating	[1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384 1474608 ...]
15355717786080 non-terminating	[15355717786080 44534663601120 144940087464480 ...]

```