Easy Math
Given nn integers a1,a2,…,ana1,a2,…,an, check if the sum of their square root a1−−√+a2−−√+⋯+an−−√a1+a2+⋯+an is a integer.
Input
The input consists of multiple tests. For each test:
The first line contains 11 integer nn (1≤n≤1051≤n≤105). The second line contains nnintegers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109).
Output
For each test, write "Yes
" if the sum is a integer, or "No
" otherwise.
Sample Input
2
1 4
2
2 3
Sample Output
Yes
No
思路:求有每个数他开方再平方是否等于原数
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a;
int main()
{
int n,flag;
while(~scanf("%d",&n))
{
flag =0;
for(int i=0;i<n;++i)
{
scanf("%d",&a);
if(a == sqrt(a)*sqrt(a))
{
}
else{
flag =1;
}
}
if(flag == 1)
{
printf("No\n");
}
else{
printf("Yes\n");
}
}
return 0;
}