C++ Solution |SIMPLE DSU APPROACH
Intuition\nits similar problem like greatest commom divisor traversal\n\n# Approach\n Describe your approach to solving the problem. \nstoring the contribution 
# Intuition\nits similar problem like greatest commom divisor traversal\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nstoring the contribution of each index in prime factors vector\nlike for which no the prime factor will be 3 \n\n\n# Code\n```\nclass DisjointSet{\npublic:\n    vector<int>rank,size,parent;\n     DisjointSet(int n){\n        rank.resize(n+1,0);\n        size.resize(n+1,1);\n        parent.resize(n+1);\n\n        //Initially,every node is a prent of itself \n        for(int i=0;i<=n;i++){\n            parent[i]=i;\n        }\n    }\n\n    //FIND ULTIMATE PARENT\n    int findUltimatePrent(int node){\n            return node==parent[node]?node:parent[node]=findUltimatePrent(parent[node]) ;\n    }\n\n    //UNION BY RANK\n    void UnionByRank(int u,int v){\n        int ulp_u = findUltimatePrent(u);\n        int ulp_v = findUltimatePrent(v);\n\n       \n        if(ulp_u==ulp_v) return;\n\n        \n        if(rank[ulp_u]<rank[ulp_v]){\n            parent[ulp_u]=ulp_v;\n        }\n\n         \n        if(rank[ulp_u]>rank[ulp_v]){\n            parent[ulp_v]=ulp_u;\n        }\n\n        if(rank[ulp_u]==rank[ulp_v]){\n            parent[ulp_u]=ulp_v; \n            rank[ulp_v]++;\n        }\n    }\n    void UnionBySize(int u,int v){\n        int ulp_u = findUltimatePrent(u);\n        int ulp_v = findUltimatePrent(v);\n \n        if(ulp_u == ulp_v) return;\n\n        if(size[ulp_u]<size[ulp_v]){\n            parent[ulp_u]=ulp_v;\n            size[ulp_v]+=size[ulp_u];\n        }\n\n       \n        if(size[ulp_u]>size[ulp_v]){\n            parent[ulp_v]=ulp_u;\n            size[ulp_u]+=size[ulp_v];\n        }\n\n        \n        if(size[ulp_u]==size[ulp_v]){\n            parent[ulp_u]=ulp_v; \n            size[ulp_v]+=size[ulp_u]; \n        }\n    }\n};\n\nclass Solution {\npublic:\n    int largestComponentSize(vector<int>& nums) {\n    \n       map<int,vector<int>>factor; \n       int n = nums.size();\n       for(int i=0;i<n;i++){\n           for(int j=2;j*j<=nums[i];j++){\n               if(nums[i]%j==0){\n                   factor[j].push_back(i);\n                   while(nums[i]%j==0) nums[i]/=j; \n               }\n           }\n          \n           if(nums[i]>1) factor[nums[i]].push_back(i) ; \n       }\n       \n       DisjointSet ds(n);\n       for(auto&it:factor){\n           vector<int>prime_pos=it.second;\n          \n           for(int i=1;i<prime_pos.size();i++){\n               ds.UnionBySize(prime_pos[i-1],prime_pos[i]);\n           }\n       }\n\n       \n       int mx  = 0 ;\n       for(int i=0;i<n;i++){\n         /// cout<<ds.size[i]<<" ";\n           mx=max(mx,ds.size[i]);\n       }\n       return mx;\n    }\n};\n```
['C++']