把所有数的立方因子除去,那么一个数可以和它组成立方的数是确定的,统计就行
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long LL; const int N=1e6+5; const int INF=0x3f3f3f3f; int vis[N],prime[1005],cnt; void getprime(){ bool v[1020]; memset(v,0,sizeof(v)); for(int i=2;i*i<=1000;++i){ if(v[i])continue; for(int j=i*i;j<=1000;j+=i) v[j]=1; } for(int i=2;i<=1000;++i) if(!v[i])prime[++cnt]=i; } int main(){ int T,n; getprime(); // printf("%d ",cnt); scanf("%d",&T); while(T--){ memset(vis,0,sizeof(vis)); scanf("%d",&n); LL ans=0; for(int i=1;i<=n;++i){ LL t,t1;scanf("%lld",&t),t1=t,t=1; LL aim=1;bool flag=0; for(int j=1;j<=cnt&&prime[j]<=t1/prime[j];++j){ int tmp=0; while(t1%prime[j]==0)t1/=prime[j],++tmp; if(tmp%3==1){ t*=prime[j]; aim*=prime[j]; if(aim>N-5)flag=1; aim*=prime[j]; if(aim>N-5)flag=1; } else if(tmp%3==2){ t*=prime[j]*prime[j]; aim*=prime[j]; if(aim>N-5)flag=1; } } if(!flag){ if(t1>1){ t*=t1; aim*=t1; if(aim>N-5)flag=1; aim*=t1; if(aim>N-5)flag=1; } if(!flag)ans+=vis[aim]; } ++vis[t]; } printf("%lld ",ans); } return 0; }