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.
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).
For each test, write "Yes
" if the sum is a integer, or "No
" otherwise.
2
1 4
2
2 3
Yes
思路:
判断是不是整数
代码:
#include
#include
using namespace std;
int main(){
int n;
cin>>n;
while(~scanf("%d",&n)){
int flag=0;
while(n--)
{
int num;
scanf("%d",&num);
int tmp=sqrt(num);
if(tmp*tmp!=num){
flag=1;
}
}
if(flag) cout<<"No"<