

Consider ARR = [2, 4, 5, 15], all possible good subsets following the given conditions are (2), (4), (5), (15), (2,4), and (5,15). Hence, the total number of good subsets is 6 in this case.
The first line of the input contains an integer, 'T,’ denoting the number of test cases. The 'T' test cases follow.
The first line of each test case contains a single integer, 'N', denoting the number of elements in the array.
The second line of each test case contains 'N' space-separated integers denoting the elements of the array 'ARR'.
For each test case, print a single integer - the total number of good subsets.
Print the output of each test case in a separate line.
1 <= T <= 10
1 <= N <= 10^5
1 <= ARR[i] <= 10^5
All elements present in the array ARR are unique.
Time limit: 1 sec
The idea is to use a recursive approach to find all subsets of the array. The recursive idea is very clear that there are only two choices for any element in the array, either to include the element in the subset or do not include the element. Using this idea, we can find all subsets recursively, and we will check if the subset follows the given conditions.
We will define a function allSubsets(ARR, subset, index) to find all subsets of ARR. We will create an array subset to store the numbers present in the subset. Our final answer will be the total number of good subsets following the given conditions.
A simple method is to sort the given array and traverse through the array to find the total number of good subsets with each array element as the rear element of the subset.
Our approach will be to construct an array distinctSubsets to store the total number of subsets following the given condition with ARR[i] as the rear element of the subset. We will sort the array ARR. We will iterate index from 0 to N-1, and in each iteration, we will iterate pos from 0 to index-1.
Now, there will be two cases,
The subset elements can only be arranged in increasing order such that each element divides the next element in order. Due to this, we are sorting the array and traversing through the array to find the total number of subsets in which we can append the array element.
In the previous approach, we are traversing through the array to find the total number of subsets in which we can append the array element, but in this approach, we will be traversing through all the possible elements that we can append in the subset, i.e., its multiples. We are trying to create a subset such that each element divides the next element of the subset. So, our approach will be to traverse through all possible elements such that the rear element of the subset divides that particular element.
We will construct an array distinctSubsets of size Max(ARR), and we will sort the array ARR. We will iterate index from 0 to N-1, and in each iteration, we will iterate pos from 2*ARR[index] to Max(ARR) and set element as ARR[index].