# Task
 Given an integer `product`, find the smallest positive integer the product of whose digits is equal to product. If there is no such integer, return -1 instead.

# Example

 For `product = 1`, the output should be `11`;
 
 `1 x 1 = 1` (1 is not a valid result, because it has only 1 digit)
 
 For `product = 12`, the output should be `26`;
 
 `2 x 6 = 12`
 
 For `product = 19`, the output should be `-1`.
 
 No valid result found.
 
 For `product = 450`, the output should be `2559`.
 
 `2 x 5 x 5 x 9 = 450`
 
 For `product = 581`, the output should be `-1`.
 
 No valid result found. 
 
 Someone says the output should be `783`, because `7 x 83 = 581`.
 
 Please note: `83` is not a **DIGIT**.
 
# Input/Output


 - `[input]` integer `product`

    Constraints: `0 ≤ product ≤ 600`.


 - `[output]` a positive integer

Difficulty: EASY
Starter code: def digits_product(product):
	

Solutions:
def digits_product(product):
	if product < 10:
		return 10 + product
	n = ''
	for d in range(9, 1, -1):
		while not product % d:
			n += str(d)
			product //= d
	return int(n[::-1]) if product == 1 else -1


from functools import reduce
from operator import mul

def digits_product(product):
	if product == 0:
		return 10
	elif len(str(product)) == 1:
		return int('1' + str(product))
	temp = product
	digits = []
	units = list(range(9, 1, -1))
	for i in units:
		if product % i == 0:
			exponent = 0
			while product % i == 0:
				exponent += 1
				product //= i
			digits.append((i, exponent))
	res = ''
	for (digit, occurances) in digits:
		res += str(digit) * occurances
	return int(res[::-1]) if res and reduce(mul, [int(i) for i in res]) == temp else -1


def digits_product(product):
	if product < 10:
		return 10 + product
	a = ''
	while product > 1:
		for i in range(9, 1, -1):
			if product % i == 0:
				a += str(i)
				product //= i
				break
		else:
			return -1
	return int(a[::-1])


from functools import reduce
from operator import mul
PRODUCTS = {}
for n in range(10, 5000):
	dig_prod = reduce(mul, map(int, str(n)))
	if dig_prod < 600 and dig_prod not in PRODUCTS:
		PRODUCTS[dig_prod] = n

def digits_product(product):
	return PRODUCTS.get(product, -1)


def digits_product(product):
	if product < 10:
		return 10 + product
	lst = []
	for d in range(9, 1, -1):
		while product % d == 0:
			product /= d
			lst.append(d)
	return -1 if product != 1 else int(''.join(map(str, lst[::-1])))


def prime_factors(num):
	factors = []
	while num % 2 == 0:
		factors.append(2)
		num //= 2
	i = 3
	max_factor = num ** 0.5
	while i <= max_factor:
		while num % i == 0:
			factors.append(i)
			num //= i
			max_factor = num ** 0.5
		i += 2
	if num > 1:
		factors.append(num)
	return factors

def digits_product(product):
	if product == 0:
		return 10
	elif product == 1:
		return 11
	factors = prime_factors(product)
	if not set(factors) <= {2, 3, 5, 7}:
		return -1
	if len(factors) == 1:
		return 10 + factors[0]
	factors = ''.join((str(f) for f in factors))
	factors = ''.join(sorted(factors.replace('33', '9')))
	factors = factors.replace('222', '8')
	factors = factors.replace('23', '6')
	factors = factors.replace('22', '4')
	if len(factors) == 1:
		factors += '1'
	return int(''.join(sorted(factors)))


import math

def getNumber(n):
	N = n
	number = ''
	divisor = 9
	while divisor > 1 and n > 0:
		if n % divisor == 0:
			number += str(divisor)
			n //= divisor
		else:
			divisor -= 1
	return int(number[::-1]) if number and n == 1 else -1

def digits_product(product):
	if product == 0:
		return 10
	if 0 < product < 10:
		return 10 + product
	return getNumber(product)


def digits_product(product):
	if product < 10:
		return 10 + product
	res = factorization(product)
	for i in res:
		if i >= 10:
			return -1
	reduce(res)
	total = 0
	for (i, j) in enumerate(res):
		total += 10 ** (len(res) - i - 1) * j
	return total

def factorization(n):
	res = []
	factor = 2
	while factor * factor <= n:
		if n % factor == 0:
			res.append(factor)
			n //= factor
			factor = 2
		else:
			factor += 1
	res.append(n)
	return res

def is_prime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def reduce(res):
	while res.count(3) >= 2:
		res.remove(3)
		res.remove(3)
		res.append(9)
	while res.count(2) >= 3:
		res.remove(2)
		res.remove(2)
		res.remove(2)
		res.append(8)
	while res.count(2) >= 1 and res.count(3) >= 1:
		res.remove(2)
		res.remove(3)
		res.append(6)
	while res.count(2) >= 2:
		res.remove(2)
		res.remove(2)
		res.append(4)
	res.sort()


from math import gcd, log
from operator import mul
from functools import reduce

def digits_product(product):
	if product <= 1:
		return 10 + product
	count = lambda p: round(log(gcd(product, p ** 9), p))
	(n2, n3, n5, n7) = map(count, [2, 3, 5, 7])
	digits = [5] * n5 + [7] * n7 + [8] * (n2 // 3) + [9] * (n3 // 2)
	n2 %= 3
	n3 %= 2
	if n3 and n2:
		digits.append(6)
		n3 -= 1
		n2 -= 1
	digits.extend([4] * (n2 // 2) + [2] * (n2 % 2) + [3] * n3)
	if len(digits) <= 1:
		digits.append(1)
	return int(''.join(map(str, sorted(digits)))) if reduce(mul, digits) == product else -1


def digits_product(product):
	if product < 10:
		return 10 + product
	facs = []
	for p in (2, 3, 5, 7):
		while product % p == 0:
			facs.append(p)
			product //= p
	if product != 1:
		return -1
	while facs.count(3) >= 2:
		facs.remove(3)
		facs.remove(3)
		facs.append(9)
	while facs.count(2) >= 3:
		facs.remove(2)
		facs.remove(2)
		facs.remove(2)
		facs.append(8)
	while 2 in facs and 3 in facs:
		facs.remove(2)
		facs.remove(3)
		facs.append(6)
	while facs.count(2) >= 2:
		facs.remove(2)
		facs.remove(2)
		facs.append(4)
	return int(''.join(sorted((str(x) for x in facs))))