結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 22:13:29 |
| 言語 | Haskell (9.10.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,018 bytes |
| 記録 | |
| コンパイル時間 | 6,008 ms |
| コンパイル使用メモリ | 174,464 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-31 21:16:46 |
| 合計ジャッジ時間 | 2,666 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 RE * 1 |
コンパイルメッセージ
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
ソースコード
import Control.Applicative
import Control.Monad
import Data.Int
import Data.List (sort)
getInts :: IO [Int64]
getInts = map (fromIntegral . read) . words <$> getLine
factor :: Int64 -> [(Int64, Int64)]
factor x = helper x 2
where
helper x y
| y * y > x = if x /= 1 then [(x, 1)] else []
| x `mod` y == 0 = let (n, x') = f x y 0
in (y, n) : helper x' (y+1)
f x y a
| x `mod` y == 0 = f (x`div`y) y (a+1)
| otherwise = (a, x)
main = do
q <- readLn
query <- replicateM q getInts
let
m = 100000009
count n x t
| n `mod` x == 0 = count (n`div`x) x (t+1)
| otherwise = t
f x 0 = [x]
f x n = x : (f x' (n-1))
where
x' = 1+(x*x`mod`m + x*12345`mod`m) `mod` m
g [seed,n,k,b] = minimum $ map h fs
where
xs = f seed n
fs = factor b
h (p,q) = (`div`q) . sum . take (fromIntegral k) . sort $ map (\x -> count x p 0) xs
in mapM (print . g) query
tottoripaper