summaryrefslogtreecommitdiff
path: root/31-41/36.hs
blob: cb9d09a65b1511c38f5b3563790089ab81b95136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import Data.List (group)

primeFactors :: Int -> [Int]

primeFactors x = factor x primes
    where primes = filterPrime [2..]
          filterPrime (p:xs) = p:filterPrime [x | x <- xs, x `mod` p /= 0]
          factor x l@(p:xs)
            | p > x = []
            | x `mod` p == 0 = p:factor (x `div` p) l
            | otherwise = factor x xs

primeFactorsMult :: Int -> [(Int, Int)]

primeFactorsMult x = [(head l, length l) | l <- group $ primeFactors x]