結果

問題 No.144 エラトステネスのざる
コンテスト
ユーザー Kaito Udagawa
提出日時 2015-02-06 11:56:29
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 632 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,777 ms
コンパイル使用メモリ 191,360 KB
実行使用メモリ 1,066,276 KB
最終ジャッジ日時 2026-03-08 03:25:29
合計ジャッジ時間 27,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 7 TLE * 6 MLE * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Functor
import Debug.Trace

primes :: Int -> Double -> [(Double, Int)]
primes n p = sieve (zip (replicate (n - 1) 1.0) [2..n])
  where
    sieve [] = []
    sieve ((l,x):xs) = (l,x):sieve (take (x - 1) xs ++ erase x (drop (x - 1) xs))
    erase y ((l,x):xs)
      | x `mod` y == 0 = ((1 - p) * l, x):erase y xs
      | otherwise = (l, x):erase y xs
    erase _ [] = []

main =
  do
    l <- words <$> getLine
    let n = read (l !! 0) :: Int
        p = read (l !! 1) :: Double
        k = primes n p
    (putStrLn . show) (foldl (\ r (v, _) -> v + r) 0.0 k)
0