Phoenix and Puzzletime
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.
题意:
一个正方形 能否由n个相同的等腰直角三角形构成
思路:
一个最基本的判别方式 如果n等于2的n次方 是ok的 因为总是切分
2大正方形由小正方形构成 我们需要知道能够组成几个小正方形
小正方形的个数是否为一个平方数
因为 如果小正方形的个数为平方数的话 那么正好可以 组成一个大的正方形
由于找小正方形不知道是哪一个 所以遍历一波即可
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<queue>
#define inf 1e9
using namespace std;
typedef long long ll;
ll n,m,k;
const int maxn=1e6+199;
int main(){
int _;
cin>>_;
while(_--){
cin>>n;
if(n&1){
cout<<"NO"<<endl;
continue;
}
int flag=0;
m=n;
while(n){
if(n%2!=0&&n!=1){
flag=1;
break;
}
n/=2;
}
if(flag){
int bj=0;
double a[100];
a[0]=1;
for(int i=1;i<=10;i++){
a[i]=a[i-1]*2;
}
for(int i=1;i<=10&&a[i]<m;i++)
if(int(sqrt(m/a[i]))*int(sqrt(m/a[i]))==m/a[i]){
bj=1;
break;
}
if(bj){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}else{
cout<<"YES"<<endl;
}
}
return 0;
}```