Python3 official solution with improvement - Largest Component Size by Common Factor
\nclass UF:        \n    def __init__(self) -> None:\n        self.parent = {}\n        self.sz = {}\n        self.count = 0\n        \n    def add(self, p):   
```\nclass UF:        \n    def __init__(self) -> None:\n        self.parent = {}\n        self.sz = {}\n        self.count = 0\n        \n    def add(self, p):    \n        if p not in self.parent:\n            self.parent[p] = p\n            self.sz[p] = 1\n            self.count += 1\n                          \n    def find(self, p: int) -> int:\n        while p != self.parent[p]:\n            self.parent[p] = self.parent[self.parent[p]]\n            p = self.parent[p]\n        return p  \n              \n    def union(self, p: int, q: int) -> None:\n        i = self.find(p)\n        j = self.find(q)             \n        if i == j:    \n            return \n        if self.sz[i] > self.sz[j]:                 \n            self.parent[j] = i\n            self.sz[i] += self.sz[j]\n        else:             \n            self.parent[i] = j\n            self.sz[j] += self.sz[i]                                           \n        self.count -= 1 \n        \nclass Solution:\n    def largestComponentSize(self, A: List[int]) -> int:\n        def fac(n): \n            for i in range(2, int(n**0.5)+1):\n                if n % i == 0:\n                    n //= i\n                    return set((i,)) | fac(n)\n            return set((n,))\n        \n        @lru_cache(None) \n        def group_id(p):\n            return uf.find(p)\n        \n        uf = UF()\n        c = Counter() \n        for n in A:\n            factors = fac(n)\n            if (key := tuple(sorted(factors))) not in c:\n                p = factors.pop()\n                uf.add(p)\n                for q in factors:\n                    uf.add(q)\n                    uf.union(p, q)\n            c[key] += 1\n        if uf.count == 1:\n            return len(A)            \n        groups = Counter()\n        for factors, value in c.items():\n            groups[group_id(factors[0])] += value\n        return groups.most_common()[0][1]\n```
['Union Find', 'Python', 'Python3']