結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー pekempeypekempey
提出日時 2016-08-11 03:35:13
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 174,976 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-04-25 01:12:36
合計ジャッジ時間 2,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 3 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 7 ms
5,632 KB
testcase_20 AC 26 ms
12,928 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 35 ms
13,056 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 16 ms
7,552 KB
testcase_33 AC 86 ms
32,896 KB
testcase_34 AC 86 ms
32,640 KB
testcase_35 AC 34 ms
13,056 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)
    ps <- newSTRef [2] :: ST s (STRef s [Int])
    forM_ [3, 5 .. n] $ \i -> do
        v <- readArray a i
        when v $ do
            modifySTRef ps (i:)
            forM_ [i * i, i * i + i .. n] $ \j -> writeArray a j False
    readSTRef ps

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

0