题解:
注意到不能同时选的数是一一对应的。
那么直接Pollard-Rho即可。
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
typedef long long LL;
typedef __int128 IL;
typedef map <LL,LL> Map;
typedef Map :: iterator it_m;
const int RLEN=1<<18|1; const LL mod=998244353998244353LL;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob) ? -1 : *ib++;
}
inline LL rd() {
char ch=nc(); LL i=0,f=1;
while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
return i*f;
}
inline LL mul(LL a,LL b,LL md) {return (IL)a*b%md;}
inline LL power(LL a,LL b,LL md,LL rs=1) {for(;b;b>>=1,a=mul(a,a,md)) if(b&1) rs=mul(rs,a,md); return rs;}
Map s1,s2; int bz=0;
namespace RHO {
const int pr[]={2,3,5,7,11,13,17,19,23};
vector <LL> vec;
inline LL gcd(LL a,LL b) {return b ? gcd(b,a%b) : a;}
inline LL rho(LL nn,LL c) {
LL x=rand()%nn+1, y=x, k=2;
for(int i=1;;i++) {
x=(mul(x,x,nn)+c)%nn;
LL p=gcd(abs(y-x),nn);
if(p!=1) return p;
if(i==k) k<<=1, y=x;
}
}
inline bool mr(LL nn) {
if(nn<=3) return true;
if((nn%6)!=1 && (nn%6)!=5) return false;
LL s1=nn-1, s2=0;
while(!(s1&1)) s1>>=1, ++s2;
for(int i=0;i<=8;i++) {
if(nn==pr[i]) return true;
LL p=power(pr[i],s1,nn);
for(int j=1;j<=s2 && p!=1;++j) {
LL t=mul(p,p,nn);
if(t==1 && p!=nn-1 && p!=1) return false;
p=t;
}
if(p!=1) return false;
} return true;
}
inline void solve(LL nn) {
if(mr(nn)) {vec.push_back(nn%mod); return;}
LL g=rho(nn,rand()%nn);
while(g==nn) g=rho(nn,rand()%nn);
solve(nn/g); solve(g);
}
inline void fac(LL nn) {
if(nn==1) return (void)(bz++);
vec.clear();
solve(nn);
sort(vec.begin(),vec.end());
LL a1=1, a2=1;
for(int i=0,lst=0;i<vec.size();++i) {
++lst;
if(i!=vec.size()-1 && vec[i+1]==vec[i]) continue;
lst%=3;
if(lst) a1=mul(a1,power(vec[i]%mod,lst,mod),mod), a2=mul(a2,power(vec[i]%mod,3-lst,mod),mod);
lst=0;
}
if(a1==1) return (void)(bz++);
s2[a1]=a2; s2[a2]=a1; ++s1[a1];
}
}
int main() {
int n=rd(); srand(time(0));
for(int i=1;i<=n;i++) RHO::fac(rd());
int ans=0;
for(it_m it=s1.begin();it!=s1.end();++it)
if((it->second)>s1[s2[it->first]] || ((it->second)==s1[s2[it->first]] && it->first>=s2[it->first])) ans+=it->second;
cout<<ans+(bz>0)<<'\n';
}