結果

問題 No.36 素数が嫌い!
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-10-27 12:15:45
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,402 ms / 5,000 ms
コード長 954 bytes
コンパイル時間 3,709 ms
コンパイル使用メモリ 160,920 KB
実行使用メモリ 48,360 KB
最終ジャッジ日時 2023-09-09 07:23:59
合計ジャッジ時間 8,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
22,220 KB
testcase_01 AC 22 ms
11,812 KB
testcase_02 AC 3 ms
6,868 KB
testcase_03 AC 3 ms
6,960 KB
testcase_04 AC 2 ms
6,880 KB
testcase_05 AC 3 ms
7,640 KB
testcase_06 AC 4 ms
7,896 KB
testcase_07 AC 4 ms
8,060 KB
testcase_08 AC 2 ms
7,052 KB
testcase_09 AC 3 ms
6,976 KB
testcase_10 AC 2 ms
7,296 KB
testcase_11 AC 312 ms
21,772 KB
testcase_12 AC 1,402 ms
48,360 KB
testcase_13 AC 1,402 ms
48,324 KB
testcase_14 AC 4 ms
8,016 KB
testcase_15 AC 2 ms
6,960 KB
testcase_16 AC 3 ms
6,924 KB
testcase_17 AC 2 ms
6,804 KB
testcase_18 AC 3 ms
6,908 KB
testcase_19 AC 32 ms
13,172 KB
testcase_20 AC 22 ms
11,904 KB
testcase_21 AC 92 ms
16,628 KB
testcase_22 AC 12 ms
10,760 KB
testcase_23 AC 6 ms
8,620 KB
testcase_24 AC 102 ms
16,528 KB
testcase_25 AC 132 ms
16,540 KB
testcase_26 AC 351 ms
32,200 KB
testcase_27 AC 22 ms
11,904 KB
testcase_28 AC 343 ms
32,280 KB
testcase_29 AC 7 ms
9,020 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

-- | Generates the sequence of prime numbers.
-- Based on <http://qiita.com/little_Haskeller/items/614a3ae20a517c19bb1f this article> .
primes2 :: Integral a => [a]
primes2 = map fromIntegral primes2'
    where
        primes2' = [2, 3, 5] ++ sieve2 5 7 (drop 2 primes2')
        sieve2 m s (p : ps) = [n | n <- ns, gcd m n == 1] ++ sieve2 (m * p) (p * p) ps
            where ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]

-- | Factorizes the given integer using 'primes2'.
-- Based on <https://wiki.haskell.org/Testing_primality this page>.
factorize2 :: Integral a => a -> [a]
factorize2 1 = []
factorize2 n = factorize2' n primes2
    where
        factorize2' n ps@(p : pr)
            | p * p > n = [n]
            | r == 0    = p : factorize2' q ps
            | otherwise = factorize2' n pr
            where (q, r) = quotRem n p

main :: IO ()
main = putStrLn . (\n -> if 3 <= (length $ factorize2 n) then "YES" else "NO") =<< readLn
0