結果

問題 No.843 Triple Primes
ユーザー サブライム野郎サブライム野郎
提出日時 2019-07-26 20:03:00
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 157,016 KB
実行使用メモリ 22,128 KB
最終ジャッジ日時 2023-09-15 00:27:32
合計ジャッジ時間 4,445 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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]]
0