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


perfectTotient: procedure options(main);
    gcd: procedure(aa, bb) returns(fixed);
        declare (aa, bb, a, b, c) fixed;
        a = aa; 
        b = bb;
        do while(b ^= 0);
            c = a;
            a = b;
            b = mod(c, b);
        end;
        return(a);
    end gcd;
 
    totient: procedure(n) returns(fixed);
        declare (i, n, s) fixed;
        s = 0;
        do i=1 to n-1;
            if gcd(n,i) = 1 then s = s+1;
        end;
        return(s);
    end totient;
 
    perfect: procedure(n) returns(bit);
        declare (n, x, sum) fixed;
        sum = 0;
        x = n;
        do while(x > 1);
            x = totient(x);
            sum = sum + x;
        end;
        return(sum = n);
    end perfect;
 
    declare (n, seen) fixed;
    seen = 0;
    do n=3 repeat(n+2) while(seen<20);
        if perfect(n) then do;
            put edit(n) (F(5));
            seen = seen+1;
            if mod(seen,10) = 0 then put skip;
        end;
    end;
end perfectTotient;