3 Separate Class Easy to understand || UnionFind Class || Sieve Class || C++
\nclass UnionFind {\n    public:\n        vector < int > par, SIZ;\n        UnionFind( int sz = 100005 ) {\n            for ( int i = 0; i < sz; ++i ) {\n      
```\nclass UnionFind {\n    public:\n        vector < int > par, SIZ;\n        UnionFind( int sz = 100005 ) {\n            for ( int i = 0; i < sz; ++i ) {\n                par.push_back( i );\n                SIZ.push_back( 0 );\n            }\n        }\n\n        int find_root( int u ) {\n            if ( par[ u ] != u )\n                par[ u ] = find_root( par[ u ] );\n\n                return par[ u ];\n        }\n\n        void merge( int u, int v ) {\n            if ( find_root( u ) != find_root( v ) ) {\n                if ( SIZ[ par[ u ] ] <= SIZ[ par[ v ] ] )   swap( u, v );\n\n                SIZ[ par[ u ] ] += SIZ[ par[ v ] ];\n                par[ par[ v ] ] = par[ u ];\n            }\n        }\n};\n\nclass Sieve {\n    public:     \n        vector < int > sie;\n        vector < int > spf;  \n    \n        Sieve( int MSS ) {    \n            spf.resize( MSS + 7, 0 );\n            for ( int i = 2; i < MSS; ++i ) {  \n                if ( spf[ i ] == 0 ) {\n                    spf[ i ] = i;   \n                    sie.push_back( i );  \n                }    \n                for ( int j = 0; j < sie.size() && i * sie[ j ] <= MSS && sie[ j ] <= spf[ i ]; ++j ) \n                    spf[ i * sie[ j ] ] = sie[ j ]; \n            }\n        }\n};\n\nclass Solution {\n    public:\n        Sieve Sv = Sieve( 100005 );\n    \n        int largestComponentSize( vector < int > &Arr ) {\n            UnionFind UF = UnionFind();\n            \n            for ( int A : Arr ) {\n                if ( A == 1 ) {\n                    UF.SIZ[ A ] = 1;\n                    continue;\n                }\n                vector < int > E;\n                while ( A != 1 ) {\n                    E.push_back( Sv.spf[ A ] );\n                    A /= Sv.spf[ A ]; \n                }\n                \n                UF.SIZ[ UF.find_root( E[ 0 ] ) ]++;\n                \n                for ( int i = 1; i < E.size(); ++i ) \n                    UF.merge( E[ 0 ], E[ i ] );\n            }\n            \n            return *max_element( UF.SIZ.begin(), UF.SIZ.end() );\n        }\n};\n```
['Math', 'Union Find', 'C++']