import Data.Numbers.Primes
import qualified Data.Map as M
import Data.List

-- 2:  {2}
-- 3:  {3}
-- 4:  {2^2}
-- 5:  {5}
-- 6:  {2, 3}
-- 7:  {7}
-- 8:  {2^3}
-- 9:  {3^2}
-- 10: {2, 5}
-- 11: {11}
-- 12: {2, 3}
-- 13: {13}
-- 14: {2^2, 7}
-- 15: {3, 5}
-- 16: {2^4}
-- 17: {17}
-- 18: {2, 3^2}
-- 19: {19}
-- 20: {2^2, 5}

-- ==>
-- x: {2^4, 3^2, 5, 7, 11, 13, 17, 19} = 
--     16*9*5*7*11*13*17*19 = ?


factorLists :: Integer -> [[Integer]]
factorLists n = map primeFactors [2..n]

factorMaps :: Integer -> [M.Map Integer Int]
factorMaps n = map toFactorMap $ factorLists n

toFactorMap :: [Integer] -> M.Map Integer Int
toFactorMap xs = let groups = group xs
                     assocs = map toAssoc groups
                 in  M.fromList assocs

toAssoc :: [Integer] -> (Integer,Int)
toAssoc xs = (head xs, length xs)

finalMap n = M.unionsWith max $ factorMaps n

mult n = product $ map f $ M.toList $ finalMap n
 where f (x,y) = x ^ y










