判断二进制半整数

题目链接:https://ac.nowcoder.com/acm/problem/21882

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int t;
 4 long long n;
 5 int main()
 6 {
 7     cin>>t;
 8     while(t--)
 9     {
10         cin>>n;
11         if(n%2!=0 || n<4)
12         {
13             cout<<"NO"<<endl;
14             continue;
15         }
16         int cnt=0;
17         for(int i=1; i<64; i++)
18         {
19             n>>=1;
20             if(n&1)
21                 cnt++;
22         }
23         if(cnt==2 || cnt==1)
24             cout<<"YES"<<endl;
25         else
26             cout<<"NO"<<endl;
27     }
28     return 0;
29 }

 

posted @ 2022-03-15 09:54  TFLSNOI  阅读(50)  评论(0编辑  收藏  举报