本人代码在其他OJ上AC,但是在luogu上全WA。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define N 4010
using namespace std;
inline ll read(){
ll ans=0,f=1;char ch;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())ans=ans*10+ch-'0';
return ans*f;
}
ll T,x;
ll v[N+10],p[560],cnt;
void init(ll n){
for(int i=2;i<=n;i++){
if(!v[i]){
p[++cnt]=i;
v[i]=i;
}
for(int j=1;j<=cnt;j++){
if(i*p[j]>n||v[i]<p[j])break;
v[i*p[j]]=p[j];
}
}
}
ll a[560],c[560],n;
inline bool check(ll x){
n=0;
for(int i=1;i<=cnt;i++){//把小于 10^4.5的质数筛掉
if(x%p[i]==0){
a[++n]=p[i],c[n]=0;
while(x%p[i]==0){
x/=p[i];
c[n]++;
}
if(c[n]==1)return 0;
}
if(x==1)break;
}//剩下的x质因数分解后每一项次数和<=3
//如果有两项及以上,则一定有一个一次的质数,不成立
//因此x只能是某质数的平方或者立方
ll op=0;
if(x!=1){
ll t=(ll)sqrt(x);
if(t*t==x||(t-1)*(t-1)==x||(t+1)*(t+1)==x)op=1;//是平方,y1,y2中定有一个2
t=(ll)pow((double)x,(double)1/3);
if(t*t*t==x||(t-1)*(t-1)*(t-1)==x||(t+1)*(t+1)*(t+1)==x)op=2;//是立方 y1,y2中定有一个3
if(!op)return 0;
}
return 1;
//op=2时 c[i]为偶数,直接解决;c[i]为奇数,拆成3,c[i]-3
//op=3时 c[i]为偶数,直接解决;c[i]为奇数,拆成3,c[i]-3
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
init(N);
T=read();
while(T--){
x=read();
puts(check(x)?"yes":"no");
}
//fclose(stdin);fclose(stdout);
return 0;
}