Skip to content

Instantly share code, notes, and snippets.

@gorlum0
Created August 19, 2011 03:06
Show Gist options
  • Save gorlum0/1155935 to your computer and use it in GitHub Desktop.
Save gorlum0/1155935 to your computer and use it in GitHub Desktop.
codeforces - 80 - A (hs)
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-}
{-# LANGUAGE BangPatterns #-}
{-(c) gorlum0 [at] gmail.com-}
isqrt x = truncate (sqrt $ fromIntegral x)
isPrime n
| n`rem`2 == 0 = False
| otherwise = null [x | x <- [3,5.. isqrt n + 1], n`rem`x == 0]
-- n is prime here
nextPrime n
| n == 2 = 3
| otherwise = head [x | x <- [n+2,n+4..], isPrime x]
body :: [Int] -> [Bool]
body [] = []
body (n:m:xs) = (m == nextPrime n) : body xs
fmt True = "YES"
fmt False = "NO"
main = do
ws <- words `fmap` getContents
let xs = map read ws
mapM_ (putStrLn . fmt) (body xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment