main :: IO () main = interact $ show . solve . map (read :: String -> Int). words solve :: [Int] -> Int solve [x] = length $ filter check ys where ys = takeWhile (<= x) primes check :: Int -> Bool check n | (n * n - 2) `elem` ys = True | otherwise = False isPrime :: Int -> Bool isPrime 2 = True isPrime n | n < 2 = False | (n `mod` 2) == 0 = False | otherwise = testDiv 3 n where testDiv :: Int -> Int -> Bool testDiv i n | i * i > n = True | n `mod` i == 0 = False | otherwise = testDiv (i + 2) n primes :: Integral a => [a] primes = map fromIntegral $ [2,3] ++ primes' where primes' = [5] ++ f 1 7 primes' f m s (p : ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps where ns = [x + y | x <- [s, s + 6.. p * p - 2], y <- [0, 4]]