きったんの頭

Problem 1

pe1 :: Int -> Int
pe1 limit = sum[x | x <- [1..limit], mod x 3 == 0 || mod x 5 == 0]

pe1a :: Integer -> Integer
pe1a n
    | n < 3     = 0
    | otherwise = div (3 * n3 * (n3 + 1) + 5 * n5 * (n5 + 1) - 15 * n15 * (n15 + 1)) 2
         where
         n3 = div (n - 1) 3
         n5 = div (n - 1) 5
         n15 = div (n - 1) 15

main :: IO()
main = print $ pe1 1000