import Data.List import Data.Char import Data.Ratio bernoulli :: Integer -> Rational bernoulli 0 = 1 bernoulli 1 = -1 % 2 bernoulli n | n `mod` 2 /= 0 = 0 | otherwise = sum [fromIntegral (n `choosePerm` k) * (bernoulli k) * (1 % (k - n - 1)) | k <- [0..(n-1)]] choosePerm :: Integer -> Integer -> Integer choosePerm n 0 = 1 choosePerm 0 k = 0 choosePerm n k = choosePerm (n-1) (k-1) * n `div` k