#include<bits/stdc++.h>
using namespace std;
int n,num,ans;
int main()
{
scanf("%d", &n);
num = n;
while(n) ans += n&1, n >>= 1;
if(ans > 3 || num & 1 || num < 6) cout << "NO";//2的个数大于3 没和合并
else cout << "YES";//2的个数小于3 可以拆出来
return 0;
}
其实也好想的办法
数不大 暴力枚举
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=1;i<=32;i++){
for(int j=1;j<=32;j++){
for(int h=1;h<=32;h++){
if(pow(2,i)+pow(2,j)+pow(2,h)==n){
cout<<"YES";
return 0;
}
}
}
}
cout<<"NO";
return 0;
}