Skip to content

Instantly share code, notes, and snippets.

@takuma7
Created October 23, 2010 02:07
Show Gist options
  • Save takuma7/641677 to your computer and use it in GitHub Desktop.
Save takuma7/641677 to your computer and use it in GitHub Desktop.
Project Euler - Problem 3
import System.IO
main = do
putStrLn $ show $ last $ filter ((== 0) . (mod 600851475143)) (takeWhile (< (truncate (sqrt 600851475143))) prime)
prime = 2:f [3] [3,5..]
where f (x:xs) ys = let (ps, qs) = span (< x^2) ys
in ps ++ f (xs ++ ps) [z | z <- qs, z `mod` x /= 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment