Skip to content

Instantly share code, notes, and snippets.

@nnabeyang
Created February 18, 2014 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnabeyang/9070726 to your computer and use it in GitHub Desktop.
Save nnabeyang/9070726 to your computer and use it in GitHub Desktop.
素数判定
ldf :: Int -> Int -> Maybe Int
ldf k n | k ^ 2 > n = Nothing
| rem n k == 0 = Just k
| otherwise = ldf (k+1) n
prime :: Int -> Bool
prime n = case (ldf 2 n) of
Just m -> m == n
Nothing -> True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment