RosettaCodeData/Task/Perfect-totient-numbers/Maple/perfect-totient-numbers.maple
2023-07-01 13:44:08 -04:00

19 lines
435 B
Text

iterated_totient := proc(n::posint, total)
if NumberTheory:-Totient(n) = 1 then
return total + 1;
else
return iterated_totient(NumberTheory:-Totient(n), total + NumberTheory:-Totient(n));
end if;
end proc:
isPerfect := n -> evalb(iterated_totient(n, 0) = n):
count := 0:
num_list := []:
for i while count < 20 do
if isPerfectTotient(i) then
num_list := [op(num_list), i];
count := count + 1;
end if;
end do;
num_list;