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


get "libhdr"
 
let gcd(a,b) = b=0 -> a, gcd(b, a rem b)
 
let totient(n) = valof
$(  let r = 0
    for i=1 to n-1
        if gcd(n,i) = 1 then r := r + 1
    resultis r
$)
 
let perfect(n) = valof
$(  let sum = 0 and x = n
    $(  x := totient(x)
        sum := sum + x
    $) repeatuntil x = 1
    resultis sum = n
$)
 
let start() be 
$(  let seen = 0 and n = 3
    while seen < 20
    $(  if perfect(n)
        $(  writef("%N ", n)
            seen := seen + 1
        $)
        n := n + 2
    $)
    wrch('*N')
$)