Given an array arr[] of size N, the duty is to search out the utmost variety of subsets that may be obtained from the given array such that the GCD of each a and b that belong to 2 totally different subsets is 1.
Instance:
Enter: arr[] = {2, 3, 4, 5, 6}
Output: 2
Rationalization: Divide array into 2 subset corresponding to S1 = { 2, 3, 4, 6 },
S2= { 5 }, gcd for each a and b such {that a} ∈ S1 and b ∈ S2 is 1 i.e.
GCD(2, 5) = 1, GCD(3, 5) = 1, GCD(4, 5) = 1, GCD(6, 5) = 1.
Therefore most variety of subsets is 2.Enter: arr[] = { 2, 5, 13, 9, 7, 25, 21, 6 }
Output: 3
Strategy:
The concept to resolve this downside is:
For every factor of the array discover all the weather which belong to similar subset.
To do that discover parts that aren’t coprime with it. Then for these new discovered parts repeat the identical process. All these parts will belong to 1 set. In any other case, there will probably be pair from totally different subsets which aren’t coprime.
Comply with the beneath illustration for a greater understanding.
Illustration:
Think about the array arr[] = {2, 3, 4, 5, 6}
For the worth 2:
=> The non coprime parts are {4, 6}.
=> So the group will include {2, 4, 6}.For the values 4 and 6:
=> The non coprime values with 4 and 6 are {2, 6} and {2, 3, 4}
=> {2, 6} are already visited.
=> The brand new worth is 3.
=> The subset now could be {2, 4, 6, 3}.For the worth 3:
=> The non coprime values are {6}.
=> 6 already included within the subset.The leftover factor is 5:
=> There isn’t any non coprime worth for this.
=> The brand new subset {5}.Due to this fact two subsets will be fashioned {2, 4, 6, 3} and {5}.
The next steps ought to be taken to resolve this downside:
 Firstly, create two dictionaries, one for the quantity and one other for the elements.
 The primary dictionary dic1 is used to test if the quantity is already current within the checklist or not.
 For every factor in arr[], discover all the weather which can be divisible by it and retailer them in a dictionary dic2.
 Now for every factor in arr[], test whether it is current in dic1.
 If sure, then take away it from dic1 and name the operate func() recursively with the brand new dic1 and dic2.
 Within the known as operate the handed array would be the parts saved in dic2.
 The operate will probably be known as recursively till the dic1 turns into empty. At this level, we’ve discovered all of the doable combos of numbers that may be fashioned utilizing the given array.
 Print the rely of such combos.
Under is the implementation of the above strategy:
Python3

Output
2
Time Complexity: O(N^{2 }* logM) the place M is the utmost factor of the array
Auxiliary House: O(1)