fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  4. bool BS(long long s)
  5. { long long l=1,mid,r=sqrt(s);
  6. while(l<=r)
  7. { mid=(l+r)/2;
  8. if( (mid*mid)==s )
  9. return 1;
  10. else if( (mid*mid)>s )
  11. r=mid-1;
  12. else
  13. l=mid+1;
  14. }
  15. return 0;
  16. }
  17.  
  18. int main () { GG;
  19. int t; cin>>t;
  20. while(t--) {
  21. long long n,sum=0; cin>>n;
  22. int a[n];
  23. for(int i=0;i<n;i++)
  24. { cin>>a[i];
  25. sum+=a[i]; }
  26.  
  27. if( BS(sum) ) cout<<"YES\n";
  28. else cout<<"NO\n";
  29. }return 0;}
Success #stdin #stdout 0.01s 5276KB
stdin
5
1
9
2
14 2
7
1 2 3 4 5 6 7
6
1 3 5 7 9 11
4
2 2 2 2
stdout
YES
YES
NO
YES
NO