Generate and show here, the first twenty Perfect totient numbers.



Related task

   Totient function


Also see

   the OEIS entry for   perfect totient numbers.
   mrob   list of the first 54


proc nonrec gcd(word a, b) word:
    word c;
    while b ~= 0 do 
        c := a;
        a := b;
        b := c % b
    od;
    a
corp
 
proc nonrec totient(word n) word:
    word r, i;
    r := 0;
    for i from 1 upto n-1 do
        if gcd(n,i) = 1 then r := r+1 fi
    od;
    r
corp
 
proc nonrec perfect(word n) bool:
    word sum, x;
    sum := 0;
    x := n;
    while
        x := totient(x);
        sum := sum + x;
        x ~= 1
    do od;
    sum = n
corp
 
proc nonrec main() void:
    word seen, n;
    seen := 0;
    n := 3;
    while seen < 20 do
        if perfect(n) then
            write(n, " ");
            seen := seen + 1
        fi;
        n := n + 2
    od
corp