Project Euler Problem 077
primes :: [Integer] primes = 2:f [3] [3,5..] where f (x:xs) ys = ps ++ f (xs++ps) [z | z<-qs,z`rem`x/=0] where (ps,qs) = span (< x*x) ys ps :: [Int] ps = map fromIntegral $ take 5000 $ primes mulP :: Num c => [c] -> [c] -> [c] mulP (x:xs) b = zipWith (+) (map(*x)b) $ 0:mulP xs b --母関数の積 paifold :: (Enum c, Eq a, Num a, Num c) => a -> [[c]] -> [c] paifold nn xss = imp nn xss (1:[0,0..]) where --母関数の無限積 imp 0 _ acc = acc imp _ [] acc = acc imp n (x:xs) acc = imp (n-1) xs (mulP acc x) xn :: (Enum a, Num a) => Int -> [a] xn 0 = 1:[0,0..] -- 1/(1-x^n)に相当する母関数 xn n = cycle(1:replicate (n-1) 0) plist :: (Integer, Integer) plist = head $ dropWhile ((<=5000).fst) $ zip lis [0..] where lis = paifold n $ map xn ps where n = 100 --71 ok ans1 :: Integer ans1 = snd plist main :: IO () main = print $ ans1