Created
April 4, 2011 05:44
-
-
Save oskimura/901179 to your computer and use it in GitHub Desktop.
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 -optc-O3 -optc-ffast-math -cpp #-} | |
| {-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-} | |
| {-# LANGUAGE BangPatterns, OverloadedStrings, ScopedTypeVariables #-} | |
| {-# LANGUAGE NoMonomorphismRestriction #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| module Main where | |
| import Control.Applicative | |
| import Data.List | |
| import Text.Printf | |
| import Data.Array | |
| import Data.Array.IO | |
| import Data.Foldable (for_) | |
| import Data.IORef | |
| splitBy :: (a -> Bool) -> [a] -> [[a]] | |
| splitBy p [] = [] | |
| splitBy p xs = a : (splitBy p $ dropWhile p $ b) | |
| where | |
| (a, b) = break p xs | |
| split :: String -> [String] | |
| split = splitBy (==' ') | |
| divisors :: (Integral a) => a -> [a] | |
| divisors num = divisors' num [1..num] | |
| where | |
| divisors' _ [] = [] | |
| divisors' n (x:xs) | |
| | n < x * x = [] | |
| | n `mod` x == 0 = x:(n `div` x):divisors' n xs | |
| | otherwise = divisors' n xs | |
| yesOrNo :: Bool -> String | |
| yesOrNo x = if x then "YES" else "NO" | |
| f n ks = concatMap arr ds | |
| where | |
| ds = divisors n | |
| arr x = (filter ((>2) . length)) . (filter (all (==1))) . map (\ y -> (map (ar!) $ (range ((1,y),(m,y))))) $ [1..x] | |
| where m = (n `div` x) | |
| ar = listArray ((1,1),(m , x)) $ ks | |
| main = do {(n:ks:_) <- map (map read) . map split . lines <$> getContents | |
| ; let n' = head $ n in | |
| printf "%s\n" . yesOrNo . any (not .null) $ ((f n') $ ks) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment