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


perfectTotients :: [Int]
perfectTotients =
  filter ((==) <*> (succ . sum . tail . takeWhile (1 /=) . iterate φ)) [2 ..]
 
φ :: Int -> Int
φ = memoize (\n -> length (filter ((1 ==) . gcd n) [1 .. n]))
 
memoize :: (Int -> a) -> (Int -> a)
memoize f = (!!) (f <$> [0 ..])
 
main :: IO ()
main = print $ take 20 perfectTotients