"Inspur Cup" Shandong Province 6th ACM College Students Programming Contest Cube Number

List the prime numbers within 1000, and then use two numbers to represent the current number and the number he should multiply, ans+= the number of the number he should multiply, and the current number plus one

#include <bits/stdc++.h>
using namespace std;
int flag[1000006];
int prime[1009],N=0;
void init()
{
    prime[N++]=2;
    int j=2;
    for(int i=3;i<=1007;i++)
        {for(j=2;j*j<=i;j++)
    {
        if(i%j==0)break;
    }
    if(j*j>i)prime[N++]=i;
    }
}
intmain()
{
int t;
init();
scanf("%d",&t);
while(t--)
{
int n,x;
scanf("%d",&n);
memset(flag,0,sizeof(flag));
int ans=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
long long a=1,b=1;
int flag1=0;
for(int i=0;i<N&&prime[i]<=x;i++)
{
    int tmp=prime[i]*prime[i]*prime[i];
    while(x%tmp==0)x/=tmp;
    if(x%(prime[i]*prime[i])==0)
    {
        a*=prime[i]*prime[i];
        b*=prime[i];
        x/=(prime[i]*prime[i]);
    }
    if(x%prime[i]==0)
    {
        a*=prime[i];
        b*=prime[i]*prime[i];
        x/=prime[i];
    }
    if(b>1e6)flag1=1;
    if(flag1)break;
}
if(flag1)continue;
if(x>prime[N-1])continue;
ans+=flag[b];
//cout<<b<<" "<<flag[b]<<endl;
flag[a]++;
}
printf("%d\n",ans);
}
    return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325524224&siteId=291194637