C++ | Union-Find | Prime fact.
\nclass Solution {\npublic:\n    int parent[100001];\n    int find(int x)\n    {\n        if(parent[x]!=x)\n            parent[x]=find(parent[x]);\n        retu
```\nclass Solution {\npublic:\n    int parent[100001];\n    int find(int x)\n    {\n        if(parent[x]!=x)\n            parent[x]=find(parent[x]);\n        return parent[x];\n    }\n    void Union(int x,int y)\n    {\n        int px=find(x),py=find(y);\n        parent[py]=px;\n    }\n    int largestComponentSize(vector<int>& nums) \n    {\n        for(int i=0;i<=100000;i++)\n            parent[i]=i;\n        for(auto x:nums)\n        {\n            int i=2;\n            int n=x;\n            while(i*i<=n)\n            {\n                bool flag=false;\n                while(n%i==0)\n                {\n                    flag=true;\n                    n/=i;\n                }\n                if(flag)\n                    Union(x,i);\n                i++;\n            }\n            if(n>2)\n                Union(x,n);\n        }\n        int res=0;\n        unordered_map<int,int>m;\n        for(auto x:nums)\n        {\n            int pa=find(x);\n            m[pa]++;\n            res=max(res,m[pa]);\n        }\n        return res;\n    }\n};\n```
[]