Codeforces Global Round 14, B. Phoenix and Puzzle

举报
小哈里 发表于 2022/05/10 22:24:38 2022/05/10
【摘要】 problem B. Phoenix and Puzzle time limit per test2 seconds memory limit per test256 megabytes inputst...

problem

B. Phoenix and Puzzle
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.

A puzzle piece
The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all n pieces must be used (of course, the square shouldn’t contain any holes as well). Can he do it?

Input
The input consists of multiple test cases. The first line contains an integer t (1≤t≤104) — the number of test cases.

The first line of each test case contains an integer n (1≤n≤109) — the number of puzzle pieces.

Output
For each test case, if Phoenix can create a square with the n puzzle pieces, print YES. Otherwise, print NO.

Example
inputCopy
3
2
4
6
outputCopy
YES
YES
NO
Note
For n=2, Phoenix can create a square like this:

For n=4, Phoenix can create a square like this:

For n=6, it is impossible for Phoenix to create a square.

solution

#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
	int T;  cin>>T;
	while(T--){
		int n;  cin>>n;
		int ok = 0;
		if(n%4==0){
			int x = n/4;
			int xx = sqrt(x);
			if(xx*xx==x){
				ok = 1;
			}
		}
		if(n%2==0){
			int x = n/2;
			int xx = sqrt(x);
			if(xx*xx==x){
				ok = 1;
			}
		}
		if(ok==1)cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}
  
 

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/117389999

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。