Fast than 100% concise java solution
step 1. foreach element make it as distinct min prime factor save it to a map\n(key is prime factor, value is element index set).\neg. {10, 30, 18}->{2: {0,1,2}
step 1. foreach element make it as distinct min prime factor save it to a map\n(key is prime factor, value is element index set).\neg. {10, 30, 18}->{2: {0,1,2}, 3 {1,2}, 5: {0,1}}\n\nstep 2. foreach set do union and find max cnt\n\n```\n    int[] par;\n    int[] cnt;\n    private int find(int i) {\n        if (i == par[i]) return i;\n        return par[i] = find(par[i]);\n    }\n    private void union(int i, int j) {\n        int pi = find(i);\n        int pj = find(j);\n        if (pi == pj) return ;\n        par[pi] = pj;\n        cnt[pj] += cnt[pi];\n    }\n    public int largestComponentSize(int[] A) {\n        int N = A.length;\n        par = new int[N];\n        cnt = new int[N];\n        Map<Integer, Set<Integer>> prime2Idx = new HashMap<>();\n        for (int i = 0; i < N; i++) {\n            int d = 2, x = A[i];\n            while (d * d <= x) {\n                if (x % d == 0) {\n                    while (x % d == 0) x /= d;\n                    prime2Idx.putIfAbsent(d, new HashSet<>());\n                    prime2Idx.get(d).add(i);\n                }\n                d++;\n            }\n            if (x > 1) {\n                prime2Idx.putIfAbsent(x, new HashSet<>());\n                prime2Idx.get(x).add(i);\n            }\n        }\n        for (int i = 0; i < N; i++) par[i] = i;\n        Arrays.fill(cnt, 1);\n        int max = 1;\n        for (Set<Integer> s : prime2Idx.values()) {\n            int fir = s.iterator().next();\n            for (int idx : s) {\n                union(idx, fir);\n                max = Math.max(cnt[find(idx)],max);\n            }\n        }\n        return max;\n    }\n```
[]