Problem of the day
You are given a positive integer ‘N’. Find all the unique combinations of factors of the given number ‘N’. The product of the factors in each combination should be ‘N’.
You should return a list of combinations of factors. In each combination, factors must be sorted in non-decreasing order. All combinations must be placed in lexicographical order in the list. See the example for more clarity.
Note
1. Factors should be strictly greater than 1 and strictly less than ‘N’.
2. If there is no such possible combination of factors, then return an empty list.
Example:
Consider the positive integer ‘N’ = 12.
Then, we can observe that -:
12 = 2 * 2 * 3
12 = 2 * 6
12 = 3 * 4
i.e, possible combinations of factors are [2, 2, 3], [2, 6], [3, 4].
Thus, we should return list [[2,2,3], [2,6], [3, 4]]. Note that in this list all combinations are sorted in non-decreasing order, and all the combinations in the list are placed in the lexicographical order.
1 <= T <= 50
2 <= N <= 1000
Where ‘T’ is the total number of test cases, and ‘N’ is the given integer.
Time limit: 1 sec
2
5
12
0
3
2 2 3
2 6
3 4
Test case 1:
The integer 5 is a prime number, and it has no factors. Note, we consider that factors should be strictly greater than 1 and strictly less than ‘N’.
Test case 2:
See the problem statement for an explanation.
2
16
4
4
2 2 2 2
2 2 4
2 8
4 4
1
2 2