結果

問題 No.144 エラトステネスのざる
コンテスト
ユーザー Kaito Udagawa
提出日時 2015-02-06 00:43:21
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 621 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,063 ms
コンパイル使用メモリ 192,256 KB
実行使用メモリ 24,736 KB
最終ジャッジ日時 2026-03-08 02:43:27
合計ジャッジ時間 22,751 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 3 WA * 7 TLE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

readInts :: B.ByteString -> [Int]
readInts x = fst <$> mapMaybe B.readInt (B.words x)

getParams :: B.ByteString -> (Int, Int)
getParams x = (x' !! 0, x' !! 1)
  where x' = readInts x

primes :: Int -> [Int]
primes n = sieve [2..n]
  where
    sieve (x:xs) = x : sieve ([y | y <- xs, y `mod` x /= 0])
    sieve [] = []

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