测试

int main()
{
int k;
scanf("%d",&k);
while(k--)
{
int n;
scanf("%d",&n);
int a=-1,b=-1,c=-1,flag=1;
// int a[n];
//vector ve;
for(int i=0;i < n;i++)
{
int tmp; scanf("%d",&tmp);
//ve[a[i]]++;
if(a-1)
{
a=tmp;
}
else if(b
-1&&tmp!=a)
{
b=tmp;
}
else if(c-1&&tmp!=a&&tmp!=b)
{
c=tmp;
}
else if(tmp!=a&&tmp!=b&&tmp!=c)
{
flag=0;
}
}
if(flag
0&&c!=-1)
{
printf("NO ");
}
else
{
if(c-1&&b-1)
{
printf("YES ");
}
else if(b!=-1&&c==-1)
{
double f=1;
if(a > b)
{
f = (double)a/(double)b;
}
else
{
f = (double)b/(double)a;
}
if (f == int(f))
printf("YES");
else
printf("NO ");
}
else{
int max=a > b?a:b;
max=max > c?max:c;
int min=a < b?a:b;
min=min < c?min:c;
double d = max/min;
if (d == int(d))
{
double e = sqrt(d);
if (e == int(e))
printf("YES ");
else printf("NO ");
}
else
printf("NO ");
}
}
}
return 0;
}

原文地址:https://www.cnblogs.com/sappriest/p/15331189.html