結果
| 問題 |
No.1273 はじめのζ関数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-31 09:43:48 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,074 bytes |
| コンパイル時間 | 1,764 ms |
| コンパイル使用メモリ | 171,612 KB |
| 実行使用メモリ | 14,752 KB |
| 最終ジャッジ日時 | 2024-07-22 04:44:21 |
| 合計ジャッジ時間 | 8,389 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | AC * 21 TLE * 1 -- * 18 |
コンパイルメッセージ
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
ソースコード
{-# 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)