import Control.Applicative ((<$>)) import Data.List (unfoldr) main :: IO () main = solve <$> readLn >>= print solve :: Int -> Int solve n = sum . takeWhile (<=n) $ pns pns :: [Int] pns = 2 : unfoldr f 3 where isPn x = all ((/=0) . (mod x)) $ takeWhile ((<=x) . (^2)) pns f x | isPn x = Just (x, x+2) | otherwise = f (x+2)