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

28 篇文章 0 订阅

传送门
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”.

思路:

如果至少有一个数可以开根号得到整数,那么输出“YES”。

#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
#define ll long long     
double a[110];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int flag = 0;
		for(int i = 1; i <= n; i++)
		scanf("%lf",&a[i]);
		for(int i = 1; i <= n; i++)
		{
			if(sqrt(a[i]) != (int)sqrt(a[i]))
			flag++;
		}
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值