
If the given number is 36, the smallest number will be 49 as the product of digits is 36 (=4*9).
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two integers, ‘N’ denoting the given number.
For each test case, print an integer corresponding to the minimum number ‘X’ such that the product of the digits of ‘X’ is equal to ‘N’.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^6.
Time limit: 1 sec
In this approach, we will find the factors of ‘N’ as, we know the digits can be between 1 to 9, so if we found a prime factor greater than 9, the answer is not possible. After assuring that the answer is possible, we will try every number from 1 and check its digit product using the function HELPER(X) which will return the product of digits of ‘X’.So, we will return the minimum ‘X’ for which HELPER(X) is equal to ‘N’.
In this approach, we will find the factors of ‘N’ and use them to generate the required number. We know the digits can be between 1 to 9, so if we found a factor greater than 9, the answer is not possible. So, we will store the factors in the array in decreasing order, and with his factors array, we will generate the number in the reverse order of the factors as we need to find the smallest number.