Codeforces Round #716 (Div. 2) A. Perfectly Imperfect Array

Posted 小哈里

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #716 (Div. 2) A. Perfectly Imperfect Array相关的知识,希望对你有一定的参考价值。

problem

A. Perfectly Imperfect Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.

A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements.

Input
The first line contains an integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (1≤n≤100) — the length of the array a.

The second line of each test case contains n integers a1, a2, …, an (1≤ai≤104) — the elements of the array a.

Output
If there’s a subsequence of a whose product isn’t a perfect square, print “YES”. Otherwise, print “NO”.

Example
inputCopy
2
3
1 5 4
2
100 10000
outputCopy
YES
NO
Note
In the first example, the product of the whole array (20) isn’t a perfect square.

In the second example, all subsequences have a perfect square product.

A.完美不完美的数组
每次测试的时限1秒
每个测试的内存限制256 MB
输入标准输入
输出标准输出
给定长度为n的数组a,请告诉我们它是否具有非空子序列,以使其元素的乘积不是理想的平方。

如果可以通过删除一些(可能为零)元素从a获得b,则序列b是数组a的子序列。

输入
第一行包含一个整数t(1≤t≤100)-测试用例的数量。测试用例的描述如下。

每个测试用例的第一行包含一个整数n(1≤n≤100)-数组a的长度。

每个测试用例的第二行包含n个整数a1,a2,…,an(1≤ai≤104)—数组a的元素。

输出
如果存在其产品不是理想正方形的子序列,请打印“是”。否则,打印“否”。

例子
inputCopy
2
3
1 5 4
2
100 10000
outputCopy
是的

笔记
在第一个示例中,整个数组(20)的乘积不是一个完美的正方形。

在第二个示例中,所有子序列都有一个完美的平方积。

solution

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	ios::sync_with_stdio(false);
	int T;  cin>>T;
	while(T--){
		int n;   cin>>n;
		//LL ans=1;
		int ok = 1;
		for(int i = 1; i <= n; i++){
			LL x;  cin>>x;
			LL xx = sqrt(x);
			if(xx*xx!=x){
				ok = 0;
			}
		}
		//LL t = sqrt(ans);
		if(ok==1){
			cout<<"No\\n";
		}else{
			cout<<"Yes\\n";
		}
	}
	return 0;
}


以上是关于Codeforces Round #716 (Div. 2) A. Perfectly Imperfect Array的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #716 (Div. 2) C. Product 1 Modulo N

Codeforces Round #716 (Div. 2), B. AND 0, Sum Big, 快速幂结论题

Codeforces Round #716 (Div. 2) C. Product 1 Modulo N

7.26-Codeforces Round #372 (Div. 2)

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)