


-> The graph consists of 'N' vertices.
-> The ith vertex has a value 'ARR[i]'.
-> There is an edge between two vertices 'i' and 'j' (where 'i' < 'j'), if and only if GCD('ARR[i]', 'ARR[j]') is greater than 1.
The first line of input contains a single integer 'T', representing the number of test cases or queries to be run.
Then the 'T' test cases are as follows.
The first line of each test case contains a positive integer 'N', which represents the size of the array 'ARR'.
The next line contains 'N' single space-separated positive integers representing the elements of the array.
For each test case, print an integer denoting the size of the largest component in the graph.
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^3
1 <= ARR[i] <= 10^5
Where 'ARR[i]' is the ith element in the array.
Time Limit: 1 sec
In this approach, we will make the graph, for this, we will make an adjacency list to store the edges of the graph. Iterate on the vertices using two loops and add an edge between vertex i and j, if GCD('ARR[i]', ‘ARR[j]’) is greater than 1.
Now, find the size of every component in the graph. We can do this using DFS.
Two numbers have GCD greater than 1 if they have a common prime factor.
We will use DSU to find the size of components, and each set represents one component.
Initially, there will be ‘N’ sets, each containing one vertex. We will combine two sets if they have some common prime factor.
For example:
If we have given vertex values as {10, 4, 2, 5, 3, 9}.
Note: P.F., denotes Prime Factors.
Set 1 contains {10}, P.F. are {2, 5}.
Set 2 contains {4}, P.F. are {2}.
Set 3 contains {2}, P.F. are {2}.
Set 4 contains {5}, P.F. are {5}.
Set 5 contains {3}, P.F. are {3}.
Set 6 contains {9}, P.F. are {3}.
We can combine set 2 in set 1, because 2 is the common prime factor present in both sets.
Now set 1 contains {10, 4}, P.F. are {2, 5}.
We can combine set 3 in set 1, because 2 is the common prime factor present in both sets.
Now set 1 contains {10, 4, 2}, P.F. are {2, 5}.
We can combine set 4 in set 1, because 5 is the common prime factor present in both sets.
Now set 1 contains {10, 4}, P.F. are {2, 5}.
We can combine set 6 in set 5, because 3 is the common prime factor present in both sets.
Now set 5 contains {3, 9}, P.F. are {3}.
In the end, we have two sets 1 and 5.
Set 1 contains {10, 4, 2, 5}.
Set 5 contains {3,9}.
These final two sets represent the two components of the graph.