human
Can you provide a the Python program you requested given the following:
I found an interesting problem on https://leetcode.com/problems/largest-component-size-by-common-factor/:
Given a non-empty array of unique positive integers A, consider the following graph:

There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.

Return the size of the largest connected component in the graph.
 


Example 1:
Input: [4,6,15,35]
Output: 4


Example 2:
Input: [20,50,9,63]
Output: 2


Example 3:
Input: [2,3,6,7,4,12,21,39]
Output: 8

Note:

1 <= A.length <= 20000
1 <= A[i] <= 100000

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is the Python program you requested.

class Solution:
    def largestComponentSize(self, A: List[int]) -> int:
        def pfactorization(a):
            N = a
            if a >= 2 and a % 2 == 0:
                Gp[2].append(N)
                Gn[N].append(2)
                while a % 2 == 0:
                    a //= 2
            for d in range(3, math.floor(a**(1/2)) + 1, 2):
                if a % d == 0:
                    Gn[N].append(d)
                    Gp[d].append(N)
                    while a % d == 0:   a //= d
            if a > 1:
                Gp[a].append(N)
                Gn[N].append(a)
        def dfs(curr):
            if curr in seenNodes:   return 0
            seenNodes.add(curr)
            total = 1
            for p in Gn[curr]:
                if p in seenPrimes: continue
                seenPrimes.add(p)
                for owner in Gp[p]: total += dfs(owner)
            return total
        Gp = collections.defaultdict(list)
        Gn = collections.defaultdict(list)
        for a in A: pfactorization(a)   #build our graphs
        seenPrimes, seenNodes = set(), set()
        return max([dfs(a) for a in A])