Approach using Union Find
\npublic class Solution {\n    public int LargestComponentSize(int[] nums) {\n        var set = new UnionFindSet(nums.Max() + 1);\n        \n        // Calculat
```\npublic class Solution {\n    public int LargestComponentSize(int[] nums) {\n        var set = new UnionFindSet(nums.Max() + 1);\n        \n        // Calculate primes set for all elements\n        foreach (var num in nums) {\n            for (var k = 2; k * k <= num; ++k) {\n                if (num % k == 0) {\n                    set.Union(num, k);\n                    set.Union(num, num / k);\n                }\n            }\n        }\n        \n        // Count the apperance of parents, return the maxium one.\n        // All connected nodes will point to same parent\n        var map = new Dictionary<int, int>();\n        var result = 1;\n        foreach (var num in nums) {\n            var count = set.Find(num);\n            map[count] = (map.ContainsKey(count) ? map[count] : 0) + 1;\n            result = Math.Max(result, map[count]);\n        }        \n        return result;\n    }\n    \n    public class UnionFindSet {\n        private int[] parent;\n        \n        public UnionFindSet(int size) {\n            parent = new int[size];\n            for (int i = 0; i < parent.Length; ++i) {\n                parent[i] = i;\n            }\n        }\n        public void Union(int x, int y) {\n            parent[Find(x)] = parent[Find(y)];\n        }\n        public int Find(int x) {\n            if (parent[x] != x) {\n                parent[x] = Find(parent[x]);\n            }\n            return parent[x];\n        }        \n    }\n}\n```
['Union Find']