You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO sumTo :: Integer -> Integer sumTo 0 = 0 sumTo n = (n * (n + 1)) `div` 2 multSum :: Integer -> Integer multSum 0 = 0; multSum n = total_sum where three_max = n `div` 3; five_max = n `div` 5; fifteen_max = n `div` 15; three_mult = 3 * (sumTo three_max); five_mult = 5 * (sumTo five_max); fifteen_mult = 15 * (sumTo fifteen_max); total_sum = three_mult + five_mult - fifteen_mult main :: IO () main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n = read n_temp :: Integer let sum = multSum (n - 1) print (sum)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
Haskell