Python union find + Sieve Of Eratosthenes
\nclass UnionFind:\n    def __init__(self, n):\n        self.parents = [i for i in range(n+1)]\n        self.ranks = [0] * (n+1)\n    \n    def find(self, x):\n
```\nclass UnionFind:\n    def __init__(self, n):\n        self.parents = [i for i in range(n+1)]\n        self.ranks = [0] * (n+1)\n    \n    def find(self, x):\n        if x != self.parents[x]:\n            self.parents[x] = self.find(self.parents[x])\n        return self.parents[x]\n    \n    def union(self, x, y):\n        root_x, root_y = self.find(x), self.find(y)\n        if self.ranks[root_x] < self.ranks[root_y]:\n            self.parents[root_x] = root_y\n        elif self.ranks[root_x] > self.ranks[root_y]:\n            self.parents[root_y] = root_x\n        else:\n            self.parents[root_x] = root_y\n            self.ranks[root_y] += 1\n        \nclass Solution:\n    def largestComponentSize(self, nums: List[int]) -> int:\n        nums_set = set(nums)\n        max_num = max(nums)\n        uf = UnionFind(max_num)\n        is_prime = [True for _ in range(max_num+1)]\n        for num in range(2, max_num+1):\n            if is_prime[num]:\n                for composite in range(num, max_num+1, num):\n                    if composite != num:\n                        is_prime[composite] = False\n                    if composite in nums_set:\n                        uf.union(num, composite)\n        \n        cluster_to_cnt = defaultdict(int)\n        for num in nums:\n            cluster_to_cnt[uf.find(num)] += 1\n        return max([cnt for _, cnt in cluster_to_cnt.items()])\n```
[]