fork download
  1. esPrimo :: Int -> Bool
  2. esPrimo n
  3. | n < 2 = False
  4. | otherwise = not (any (\x -> n `mod` x == 0) [2..lim])
  5. where lim = floor (sqrt (fromIntegral n))
  6.  
  7. main :: IO ()
  8. main = do
  9. print (esPrimo 2) -- True
  10. print (esPrimo 4) -- False
  11. print (esPrimo 13) -- True
  12. print (esPrimo 25) -- False
  13. print (esPrimo 29) -- True
  14.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
True
False
True
False
True