


‘N’ = 90
Possible values for ‘M’ are:
1. 259 (2*5*9 = 90)
2. 3352 (3*3*5*2 = 90)
3. 2335 (2*3*3*5 = 90)
4. 952 (9*5*2 = 90), and so on.
Here, ‘259’ is the smallest possible ‘M’. Thus, you should return ‘259’ as the answer.
The first line of input contains an integer ‘T’ which denotes the number of test cases. Then, the ‘T’ test cases follow.
The first and only line of each test case contains an integer ‘N’, i.e., the given integer.
For every test case, return the smallest possible ‘M’ value. If no such ‘M’ is possible or ‘M’ cannot fit in a 32-bit signed integer, return 0.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 1000
1 <= N <= 10^9
Time limit: 1 sec
A simple approach will be to iterate through all possible ‘M’ values, i.e., from ‘1’ to ‘2147483647’ (the largest value that a signed 32-bit integer field can hold), and check if their digit multiplication is equal to ‘N’.
Algorithm:
The smallest value of ‘M’ must satisfy the following two conditions:
Example: ‘N’ = 64800
Initially ‘M = 0’, start to assign digits to ‘M’ from ‘9’ to ‘2’:
After assigning the digits, we have ‘N = 1’, which means ‘N’ is equal to the multiplication of the digits in ‘M’. Thus, you should return ‘M = 55899’ as the answer.
Algorithm: