fork(2) download
  1. {-# OPTIONS_GHC -O2 -fno-cse #-}
  2. module Main where
  3.  
  4. main = do
  5. print $ take 5 $ drop (read s-5) primes
  6.  
  7. primes :: [Int]
  8. primes = 2 : ([3,5..] `minus`
  9. foldi (\(x:xs) -> (x:) . union xs)
  10. [[x*x, x*x+2*x..] | x<- ys])
  11. where
  12. ys = 3 : ([5,7..] `minus`
  13. foldi (\(x:xs) -> (x:) . union xs)
  14. [[x*x, x*x+2*x..] | x<- ys])
  15. foldi f (x:xs) = f x (foldi f (pairs f xs))
  16. pairs f (x:y:t) = f x y : pairs f t
  17.  
  18. minus (x:xs) (y:ys) = case compare x y of
  19. LT -> x : minus xs (y:ys)
  20. EQ -> minus xs ys
  21. GT -> minus (x:xs) ys
  22. minus a b = a
  23.  
  24. union (x:xs) (y:ys) = case compare x y of
  25. LT -> x : union xs (y:ys)
  26. EQ -> x : union xs ys
  27. GT -> y : union (x:xs) ys
  28. union a b = a ++ b
stdin
2000000
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )
Linking prog ...
stdout
[32452781,32452789,32452837,32452841,32452843]