RosettaCodeData/Task/Aliquot-sequence-classifications/PARI-GP/aliquot-sequence-classifications.parigp
2023-07-01 13:44:08 -04:00

18 lines
553 B
Text

aliquot(x) =
{
my (L = List(x), M = Map(Mat([x,1])), k, m = "non-term.", n = x);
for (i = 2, 16, n = vecsum(divisors(n)) - n;
if (n > 2^47, break,
n == 0, m = "terminates"; break,
mapisdefined(M, n, &k),
m = if (k == 1,
if (i == 2, "perfect",
i == 3, "amicable",
i > 3, concat("sociable-",i-1)),
k < i-1, concat("cyclic-",i-k),
"aspiring"); break,
mapput(M, n, i); listput(L, n));
);
printf("%16d: %10s, %s\n", x, m, Vec(L));
}