ACM国際大学対抗プログラミングコンテスト(A)
via http://d.hatena.ne.jp/zyxwv/20070606
入出力はサボった。
{- http://www.acm-japan.org/past-icpc/domestic2006/contest/all_ja.html#section_A 2007.06.06 nisikawa -} import Control.Arrow progress :: Int -> Int -> [Int] progress x y = iterate (+ y) x primes :: [Int] -> [Int] primes = filter prime . filter odd where prime x = and $ map ((/= 0) . mod x) [2..x -1] newtype Dirichlet a b = Dirichlet {run :: a -> b} instance Arrow Dirichlet where arr f = Dirichlet f (Dirichlet f) >>> (Dirichlet g) = Dirichlet $ g . f first (Dirichlet f) = Dirichlet (first f) exec :: Int -> Int -> Int -> Int exec x y z | even x && even y = 0 | otherwise = run f y where f :: Dirichlet Int Int f = arr (progress x) >>> arr primes >>> arr (flip (!!) (z - 1))