結果

問題 No.1273 はじめのζ関数
ユーザー こまるこまる
提出日時 2020-10-31 09:43:48
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 161,420 KB
実行使用メモリ 11,200 KB
最終ジャッジ日時 2023-09-29 10:10:57
合計ジャッジ時間 8,340 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
11,096 KB
testcase_01 AC 63 ms
11,124 KB
testcase_02 AC 153 ms
11,088 KB
testcase_03 AC 392 ms
11,080 KB
testcase_04 AC 72 ms
11,068 KB
testcase_05 AC 42 ms
11,080 KB
testcase_06 AC 322 ms
11,084 KB
testcase_07 AC 62 ms
11,144 KB
testcase_08 AC 412 ms
11,076 KB
testcase_09 AC 212 ms
11,124 KB
testcase_10 AC 412 ms
11,100 KB
testcase_11 AC 43 ms
11,156 KB
testcase_12 AC 52 ms
11,128 KB
testcase_13 AC 412 ms
11,156 KB
testcase_14 AC 82 ms
11,200 KB
testcase_15 AC 92 ms
11,192 KB
testcase_16 AC 92 ms
11,144 KB
testcase_17 AC 72 ms
11,128 KB
testcase_18 AC 142 ms
11,148 KB
testcase_19 AC 152 ms
11,104 KB
testcase_20 AC 3 ms
6,952 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

{-# LANGUAGE BangPatterns       #-}
{-# LANGUAGE NumericUnderscores #-}

import           Control.Monad
import           Control.Monad.ST
import           Data.STRef
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM

main :: IO ()
main = do
  x <- readLn :: IO Int
  if x == 2 then putStrLn "1000000"
  else print . floor . (* 1_000_000) . sum . map (\a -> zeta a x) $ [2..1_000_000]

zeta :: Int -> Int -> Double
zeta a x = runST $ do
  res <- newSTRef (a - 1)
  rep (x - 1) $ \_ -> do
    ret <- readSTRef res
    when (ret <= 1_000_000_000_000) $ modifySTRef res (* a)
  d <- readSTRef res
  return (1.0 / fromIntegral d)

stream :: Monad m => Int -> Int -> VFSM.Stream m Int
stream !l !r = VFSM.Stream step l
  where
    step x
      | x < r     = return $ VFSM.Yield x (x + 1)
      | otherwise = return $ VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] stream #-}

rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep n = flip VFSM.mapM_ (stream 0 n)
{-# INLINE rep #-}

rep2 :: Monad m => (Int -> m ()) -> m ()
rep2 = flip VFSM.mapM_ (stream 2 1_000_000)
0