题目
我的思路
将所有a数组的数分解质因子,两个相同的质因子或者三个不同的质因子相乘一定是超级合数,所以用map统计质因子的个数,在用cnt统计“落单的”质因子的数量。
思路是没有问题的,只是对质因子的处理过于繁琐超时了
AC代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
int T=1;
int n,a;
int main(){
cin>>T;
while(T--){
cin>>n;
int ans=0,mx=0,cnt=0;
map<int,int>mp;
for(int i=1;i<=n;i++){
cin>>a;mx=max(mx,a);
for(int j=2;j*j<=a;j++){
while(a%j==0){
a=a/j;
mp[j]++;
}//while
}//for
if(a!=1) mp[a]++;
}//for
for(auto q:mp){
ans+=q.second/2;
cnt+=q.second%2;
}
cout<<ans+cnt/3<<endl;
}//while
return 0;
}