fork download
  1. isPerfect :: (Integral a) => a -> Bool
  2. isPerfect n = result
  3. where limit = ceiling (sqrt (fromIntegral n))
  4. result = case filter (\k -> n`mod`k == 0) [2..limit] of
  5. (d1:d2:_) -> n == d1*d2
  6. [d1] -> n`div`d1 /= d1
  7. _ -> False
  8.  
  9. main = print (length (takeWhile (<=1000000) perfects))
  10. where perfects = filter isPerfect [6..] :: [Int]
  11.  
Success #stdin #stdout 5.4s 6264KB
stdin
Standard input is empty
stdout
209892