1915C - Can I Square - CodeForces Solution


implementation

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    a = int(input())
    b = list(map(int, input().split()))
    c = sum(b)
    ans = c ** (1/2)
    if str(ans) == str(int(ans))+'.0':
        print('YES')
    else:
        print("NO")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int

void solve(){
  lli n;
  cin>>n;
  lli a[n];
  for(lli i = 0; i < n; i++){
    cin>>a[i];
  }
  lli sum = 0;
  for(lli i = 0; i < n; i++){
    sum += a[i];
  }
  lli count = 0;
  lli num = 1;
  do{
    if (num*num == sum){
      count++;
    }
    num++;
  } while(num*num <= sum);
  if(count == 0){
    cout<<"NO"<<endl;
  } else{
    cout<<"YES"<<endl;
  }
}

int main(){
  lli t;
  cin>>t;
  while(t--){
    solve();
  }
}


Comments

Submit
0 Comments
More Questions

Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble