{-# OPTIONS_GHC -O2 -fno-cse #-} module Main where main = do s<-getLine print $ take 5 $ drop (read s-5) primes primes :: [Int] primes = 2 : ([3,5..] `minus` foldi (\(x:xs) -> (x:) . union xs) [[x*x, x*x+2*x..] | x<- ys]) where ys = 3 : ([5,7..] `minus` foldi (\(x:xs) -> (x:) . union xs) [[x*x, x*x+2*x..] | x<- ys]) foldi f (x:xs) = f x (foldi f (pairs f xs)) pairs f (x:y:t) = f x y : pairs f t minus (x:xs) (y:ys) = case compare x y of LT -> x : minus xs (y:ys) EQ -> minus xs ys GT -> minus (x:xs) ys minus a b = a union (x:xs) (y:ys) = case compare x y of LT -> x : union xs (y:ys) EQ -> x : union xs ys GT -> y : union (x:xs) ys union a b = a ++ b