Largest Component Size by Common Factor
You are given an integer array of unique positive integers nums. Consider the following graph:
- There are
nums.lengthnodes, labelednums[0]tonums[nums.length - 1]. - There is an undirected edge between
nums[i]andnums[j]ifnums[i]andnums[j]share a common factor greater than1.
Return the size of the largest connected component in the graph.
Example 1
Input
nums = [4,6,15,35]Output
4All four numbers are connected through common factors, so the largest connected component has size 4.
Example 2
Input
nums = [20,50,9,63]Output
2The largest connected components are [20,50] and [9,63], each of size 2.
Constraints
- 1 <= nums.length <= 2 * 10^4
- 1 <= nums[i] <= 10^5
- All the values of nums are unique.