😀 算法标签:二进制

求出对于给到的牛客多校7.I.xay loves or 二进制_算法​和牛客多校7.I.xay loves or 二进制_算法_02​,存在多少个牛客多校7.I.xay loves or 二进制_#include_03满足牛客多校7.I.xay loves or 二进制_算法_04

首先考虑牛客多校7.I.xay loves or 二进制_#include_03恒为牛客多校7.I.xay loves or 二进制_#include_06的情况:牛客多校7.I.xay loves or 二进制_算法的某一位为牛客多校7.I.xay loves or 二进制_#include_08牛客多校7.I.xay loves or 二进制_算法_02的对应位为牛客多校7.I.xay loves or 二进制_#include_06

再考虑牛客多校7.I.xay loves or 二进制_#include_03的情况种数:统计牛客多校7.I.xay loves or 二进制_算法牛客多校7.I.xay loves or 二进制_算法_02同一位都为牛客多校7.I.xay loves or 二进制_#include_08的位数,同时为牛客多校7.I.xay loves or 二进制_#include_08,那么对于该位牛客多校7.I.xay loves or 二进制_#include_03就有两种选择:然后牛客多校7.I.xay loves or 二进制_#include_17输出即可。

喜提WA…再读题,正整数。。。

考虑什么时候会出现牛客多校7.I.xay loves or 二进制_#include_06这种及其特殊的数字:牛客多校7.I.xay loves or 二进制_算法的某一位为牛客多校7.I.xay loves or 二进制_#include_06牛客多校7.I.xay loves or 二进制_算法_02的对应位为牛客多校7.I.xay loves or 二进制_#include_08,此时一定会出现牛客多校7.I.xay loves or 二进制_#include_03取0的情况。单独挑出来牛客多校7.I.xay loves or 二进制_#define_24即可。

#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

ll binpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}

signed main(){
int x, s; cin >> x >> s;
int cnteq = 0, cntneq = 0;
bool flag = 1;
while(x || s){
int xbit = x & 1, sbit = s & 1;
if(xbit == 1 && sbit == 0) return cout << 0 << endl, 0;
if(xbit == 1 && sbit == 1) cnteq++;
if(xbit == 0 && sbit == 1) flag = false;
x >>= 1, s >>= 1;
}
if(flag) cout << binpow(2, cnteq) - 1 << endl;
else cout << binpow(2, cnteq) << endl;
return 0;
}