import Data.Tuple import Data.List import Data.Bits import Data.Maybe import Control.Exception import qualified Data.HashMap.Strict as Map main = interact $ unlines . sol . head . allInt . (drop 1) . lines sol :: [Int] -> [String] sol ns = [show $ sum $ map sol' ns] sol' n = sum $ scanr (*) 1 $ factors n factors :: Int -> [Int] factors 1 = [] factors n = case find ((0==).(n`mod`)) $ [2..(round $ sqrt $ fromIntegral n)] of Just x -> x : factors (n`div`x) Nothing -> [n] -------------------------------------------------------------------------------- groupOn :: Int -> [a] -> [[a]] groupOn _ [] = [] groupOn n xs = let (sts, nds) = splitAt n xs in sts : groupOn n nds fromBool :: Num a => Bool -> a fromBool b = if b then 1 else 0 allInt :: [String] -> [[Int]] allInt = map ((map read) . words) swrt :: Ord a => (a, a) -> (a, a) swrt (a, b) | compare b a == LT = (b, a) | otherwise = (a, b) --------------------------------------------------------------------------------