-
-
Save gorlum0/1155935 to your computer and use it in GitHub Desktop.
codeforces - 80 - A (hs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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