primes = flip take [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
                     31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
basis n = map (\x -> 10^x) [n-1,n-2..0]

f :: [Integer] -> [Integer] -> Integer -> Integer -> Integer -> Integer -> [Integer]
f [] [] _ prod sum _
    | prod == sum = [sum]
    | otherwise   = []
f (p:ps) (b:bs) bound prod sum start
    | start == 0 && prod > sum = []
    | otherwise =
        [x | i <- [start..9], p^i <= bound,
             x <- f ps bs (div bound $ p^i) (prod * p^i) (sum + b * i) 0]

meertens n = [x | i <- [1..n], x <- f (primes i) (basis i) (10^i) 1 0 1]