Python Soluton: Sieve of Eratosthenes and Union Find
We use Sieve of Eratosthenes to find all element with common prime factor, the connet them with Union set.\n```\nclass Uni:\n\n    def init(self, arr):\n       
We use Sieve of Eratosthenes to find all element with common prime factor, the connet them with Union set.\n```\nclass Uni:\n\n    def __init__(self, arr):\n        self.arr = {i:i for i in arr}\n        self.sz = {i:1 for i in arr}\n    \n    def find(self, x):\n        if x != self.arr[x]: self.arr[x] = self.find(self.arr[x])\n        return self.arr[x]\n    \n    def same(self, x, y):\n        return self.find(x) == self.find(y)\n    \n    def merge(self, x, y):\n        x, y = self.find(x), self.find(y)\n        if x == y: return\n        if x > y: x, y = y, x\n        self.sz[x] += self.sz[y]\n        self.arr[y] = self.arr[x]\n\n\nclass Solution:\n    def largestComponentSize(self, nums: List[int]) -> int:\n        uni = Uni(nums)\n        bound = max(nums) + 1\n        isprime = [True] * bound\n        nums = set(nums)\n        for i in range(2, bound):\n            if not isprime[i]: continue\n            last = None\n            for j in range(i, bound, i):\n                isprime[j] = False\n                if j in nums:\n                    if last is None: last = j\n                    else: uni.merge(last, j)\n        return max(uni.sz.values())
[]