2015弱校联盟(1) -A. Easy Math

A. Easy Math

Time Limit: 2000ms

Memory Limit: 65536KB

Given n integers a1,a2,…,an, check if the sum of their square root a1−−√+a2−−√+⋯+an−−√ is a integer.

Input

The input consists of multiple tests. For each test:

The first line contains 1 integer n (1≤n≤105).

The second line contains n integers a1,a2,…,an (0≤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 <bits/stdc++.h>
#define LL long long
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout) using namespace std; int main()
{
int n,data;
while(~scanf("%d",&n))
{
bool flag=false;
while(n--)
{
scanf("%d",&data);
if(flag)
{
continue;
}
int ans=(int)sqrt(data);
if(ans*ans!=data)//判断是不是平方数
{
flag=true;
}
}
if(flag)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
}
return 0;
}
上一篇:springboot+mysql实现quartz集群搭建


下一篇:BestCoder Round #12 War(计算几何)