传送门
Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.
A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements.
Input
The first line contains an integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤100) — the length of the array a.
The second line of each test case contains n integers a1, a2, …, an (1≤ai≤104) — the elements of the array a.
Output
If there’s a subsequence of a whose product isn’t a perfect square, print “YES”. Otherwise, print “NO”.
思路:
如果至少有一个数可以开根号得到整数,那么输出“YES”。
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
#define ll long long
double a[110];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag = 0;
for(int i = 1; i <= n; i++)
scanf("%lf",&a[i]);
for(int i = 1; i <= n; i++)
{
if(sqrt(a[i]) != (int)sqrt(a[i]))
flag++;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}