結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー pekempeypekempey
提出日時 2016-08-11 03:18:38
言語 Haskell
(9.8.2)
結果
AC  
実行時間 243 ms / 1,000 ms
コード長 713 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 176,640 KB
実行使用メモリ 62,592 KB
最終ジャッジ日時 2024-04-25 01:12:06
合計ジャッジ時間 12,807 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
62,464 KB
testcase_01 AC 230 ms
62,592 KB
testcase_02 AC 227 ms
62,336 KB
testcase_03 AC 231 ms
62,592 KB
testcase_04 AC 225 ms
62,464 KB
testcase_05 AC 230 ms
62,592 KB
testcase_06 AC 230 ms
62,336 KB
testcase_07 AC 224 ms
62,592 KB
testcase_08 AC 230 ms
62,464 KB
testcase_09 AC 234 ms
62,592 KB
testcase_10 AC 228 ms
62,336 KB
testcase_11 AC 228 ms
62,464 KB
testcase_12 AC 228 ms
62,336 KB
testcase_13 AC 230 ms
62,592 KB
testcase_14 AC 228 ms
62,592 KB
testcase_15 AC 226 ms
62,464 KB
testcase_16 AC 232 ms
62,464 KB
testcase_17 AC 237 ms
62,592 KB
testcase_18 AC 235 ms
62,336 KB
testcase_19 AC 232 ms
62,336 KB
testcase_20 AC 234 ms
62,464 KB
testcase_21 AC 235 ms
62,592 KB
testcase_22 AC 235 ms
62,464 KB
testcase_23 AC 230 ms
62,336 KB
testcase_24 AC 234 ms
62,336 KB
testcase_25 AC 233 ms
62,464 KB
testcase_26 AC 235 ms
62,464 KB
testcase_27 AC 232 ms
62,336 KB
testcase_28 AC 228 ms
62,336 KB
testcase_29 AC 230 ms
62,592 KB
testcase_30 AC 233 ms
62,592 KB
testcase_31 AC 234 ms
62,592 KB
testcase_32 AC 231 ms
62,464 KB
testcase_33 AC 232 ms
62,464 KB
testcase_34 AC 233 ms
62,464 KB
testcase_35 AC 231 ms
62,592 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) [2..]) $ \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])
    forM_ [2..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