联萌十一大决戦の强力なるウォーミングアップA.Easy Math

2472 ワード

[テーマリンク](http://www.bnuoj.com/v3/contest_show.php?cid=6865#problem/0テーマ記述:A.Easy Math Time Limit:2000 msMemory Limit:65536 KB 64-bit integer IO format:%lld Java class name:Main Submit Stits Gven integersa 1,a 2,ancheck if the sum of their square root a 1−−−−√+a 2−−−−−−n−−−−−−−−−−√is a integer.Input The input consists of multiple test.For each test:
The first line contains 1 integer n(1≦n≦105).The second line contains n integers a 1,a 2,…,an(0≦ai≦109).
Output For each test,write‘Yes’if the sum is a integer,or‘No’others.
Sample Input 2 1 4 2 3 Sample Output Yes No
この問題はn個の数の平方根を要求しているかどうかと整数であるかどうかを直接計算して解決すればいいです。他の方面の心配が必要ではないです。水題~コードは下記の通り実現します。
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int a[100010];
int main()
{
    int n;
    double sum;
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=(double)sqrt(a[i]);//            double,             
        }
        //cout<<"sum="<<(long long)sum<<endl;
        if(sum==(long long)sum)
        {
            printf("Yes
"
); } else printf("No
"
); } return 0; }