分析 注意到要求的是最大的连通分量,那么我们可以先打素数表(唯一分解定理),然后对每个要求的数,将他们同分解出的质因子相连(维护一个并查集),然后求出最大的联通分量即可. 这里使用了筛法求素数.初始化内存时利用了一个hack. 代码 var isPrime[100005] bool var pa[100005] int var primeMap=[]int{} func initPrimeNumbers() { isPrime[0]=true for bp:=1;bp<len(isPrime);…