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

来源:互联网 发布:淮南网络宾馆 编辑:程序博客网 时间:2024/05/16 10:38

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;}
0 0
原创粉丝点击