题目传送门

题目大意

题目很简单,就是求一堆数的和是否为完全平方数,但是有几个需要注意得点:

  • 数据最大可以到 210142 \cdot 10 ^ {14},因此要开 long long。
  • 如果使用数学函数 sqrt,在数据为 long long 的时候会出错,所以要手写平方根函数(我 WA 了好多次才发现的)。

AC Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Problem: C. Can I Square?
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

int sqr(int x)
{
int t = sqrt(x);
if ((t + 1) * (t + 1) <= x)
t = t + 1;
else if (t * t > x)
t = t - 1;
return t;
}

void solve()
{
int n, cnt = 0; cin >> n;
for (int i = 1; i <= n; i ++)
{
int x; cin >> x;
cnt += x;
}
if (sqr(cnt) * sqr(cnt) == cnt) cout << "YES\n";
else cout << "NO\n";
}

signed main()
{
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T; cin >> T;
while (T --) solve();
return 0;
}