[C++] Simple solution using depth first search and prime factorization
\nclass Solution {\n    final int MAX = (int)1e5;\n    boolean[] vis;\n    int[] occ;\n    int[] LPF; // Least prime factor\n    \n    int dfs(int x) {\n       
```\nclass Solution {\n    final int MAX = (int)1e5;\n    boolean[] vis;\n    int[] occ;\n    int[] LPF; // Least prime factor\n    \n    int dfs(int x) {\n        if (x > MAX || vis[x] == true) return 0;\n        vis[x] = true;\n        \n        int cnt = occ[x];\n        \n        if (x == LPF[x]) { // if prime\n            for (int i = x+x; i <= MAX; i += x) {\n                cnt += dfs(i);\n            }\n        }\n        else if (occ[x] > 0) { // if cotains in nums array\n            for (x = x; x > 1; x /= LPF[x]) { // Log(x) prime factorization \n                cnt += dfs(LPF[x]);\n            }\n        }\n        \n        return cnt;\n    }\n    \n    public int largestComponentSize(int[] nums) {\n        occ = new int[MAX+10];\n        for (int num : nums) occ[num]++;\n        \n        LPF = new int[MAX+10];\n        for (int i = 2; i <= MAX; i++) {\n            if (LPF[i] == 0) {\n                for (int j = i; j <= MAX; j += i) {\n                    if (LPF[j] == 0) LPF[j] = i;\n                }\n            }\n        }\n        \n        vis = new boolean[MAX+10];\n        int ans = 0;\n        for (int i = 2; i <= MAX; i++) {\n            ans = Math.max(ans, dfs(i));\n        }\n        \n        return ans;\n    }\n}\n```
['Depth-First Search']