Shortest Simplest Solution | Sieve | Python
Code\n\nclass Solution:\n    def largestComponentSize(self, nums: List[int]) -> int:\n        n = len(nums)\n        mx = max(nums)\n        par = [i for i in r
# Code\n```\nclass Solution:\n    def largestComponentSize(self, nums: List[int]) -> int:\n        n = len(nums)\n        mx = max(nums)\n        par = [i for i in range(mx + 1)]\n        nums = set(nums)\n\n        def find(u):\n            if par[u] != u:\n                par[u] = find(par[u])\n            return par[u]\n    \n        def union(u, v):\n            if find(u) == find(v):\n                return\n            par[find(u)] = find(v)\n\n        for i in range(2, mx + 1):\n            for j in range(i, mx + 1, i):\n                if j in nums:\n                    union(i, j)\n        return max(Counter(find(num) for num in nums).values())\n\n```
['Python3']