結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー pekempeypekempey
提出日時 2016-08-11 03:21:56
言語 Haskell
(9.8.2)
結果
AC  
実行時間 197 ms / 1,000 ms
コード長 743 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 176,384 KB
実行使用メモリ 53,120 KB
最終ジャッジ日時 2024-04-25 01:12:33
合計ジャッジ時間 10,977 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
52,864 KB
testcase_01 AC 185 ms
53,120 KB
testcase_02 AC 196 ms
52,992 KB
testcase_03 AC 186 ms
52,992 KB
testcase_04 AC 181 ms
52,992 KB
testcase_05 AC 186 ms
52,992 KB
testcase_06 AC 197 ms
52,992 KB
testcase_07 AC 183 ms
52,864 KB
testcase_08 AC 181 ms
52,992 KB
testcase_09 AC 184 ms
52,864 KB
testcase_10 AC 184 ms
52,992 KB
testcase_11 AC 186 ms
52,992 KB
testcase_12 AC 185 ms
52,864 KB
testcase_13 AC 179 ms
52,992 KB
testcase_14 AC 178 ms
52,992 KB
testcase_15 AC 181 ms
52,864 KB
testcase_16 AC 180 ms
53,120 KB
testcase_17 AC 181 ms
52,864 KB
testcase_18 AC 180 ms
53,120 KB
testcase_19 AC 183 ms
52,992 KB
testcase_20 AC 180 ms
52,864 KB
testcase_21 AC 179 ms
52,864 KB
testcase_22 AC 181 ms
52,992 KB
testcase_23 AC 182 ms
53,120 KB
testcase_24 AC 179 ms
52,992 KB
testcase_25 AC 181 ms
52,864 KB
testcase_26 AC 182 ms
52,864 KB
testcase_27 AC 189 ms
53,120 KB
testcase_28 AC 189 ms
52,992 KB
testcase_29 AC 189 ms
53,120 KB
testcase_30 AC 192 ms
52,992 KB
testcase_31 AC 187 ms
53,120 KB
testcase_32 AC 182 ms
53,120 KB
testcase_33 AC 184 ms
53,120 KB
testcase_34 AC 183 ms
52,864 KB
testcase_35 AC 186 ms
52,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.STRef

primes :: Int -> [Int]
primes n = runST $ do
    a <- newArray (0, n) True :: ST s (STUArray s Int Bool)
    forM_ (takeWhile (\i -> i * i <= n) [3, 5..]) $ \i -> do
        v <- readArray a i
        when v $ forM_ [i * i, i * i + i .. n] $ \j -> writeArray a j False
    ps <- newSTRef [] :: ST s (STRef s [Int])
    modifySTRef ps (2:)
    forM_ [3, 5..n] $ \i -> do
        v <- readArray a i
        when v $ modifySTRef ps (i:)
    readSTRef ps

solve n l = sum . map f $ primes (10 ^ 7)
    where f p = max 0 (l - p * (n - 1) + 1)
    
main = do
    [n, l] <- map read . words <$> getLine :: IO [Int]
    print $ solve n l 
0