結果
| 問題 | 
                            No.843 Triple Primes
                             | 
                    
| コンテスト | |
| ユーザー | 
                             サブライム野郎
                         | 
                    
| 提出日時 | 2019-07-26 20:03:00 | 
| 言語 | Haskell  (9.10.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 984 bytes | 
| コンパイル時間 | 1,322 ms | 
| コンパイル使用メモリ | 171,520 KB | 
| 実行使用メモリ | 18,716 KB | 
| 最終ジャッジ日時 | 2024-07-02 06:32:27 | 
| 合計ジャッジ時間 | 4,705 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 1 TLE * 1 | 
| other | -- * 42 | 
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
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]]
            
            
            
        
            
サブライム野郎