^&^(位运算优先级)

^&^(位运算优先级)_第1张图片
比赛的签到题:
因为位运算符优先级为:^&^(位运算优先级)_第2张图片
逻辑运算符优先级为:^&^(位运算优先级)_第3张图片
所以题的公式可化为:
^&^(位运算优先级)_第4张图片
位运算:~按位取反,&相同才为1,^不同才为1,|是有1则1;
如果A&B大于0,那么C最小就是A^B,(因为相同的异或就是0);//这些都是根据位运算规则知道的;
如果A&B为0,因为C必须是>0的整数,并且算一下就可以知道结果可以为0:
因为当C=min(A,B)的时候;就可以得出公式值为0,因为min(A,B)^C异或就是0,因为相等的数就是0;所以就是最小;
所以AC代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll QP(ll x,ll n){
      ll res=1;
      while(n){
            if(n&1){
                  res=(res*x);
            }
            x=(x*x);
            n>>=1;
      }
      return res;
}
int main(){
    ll T,A,B;
    scanf("%lld",&T);
    while(T--){
          scanf("%lld %lld",&A,&B);
          ll t=A&B;
          if(t==0){
                printf("%lld\n",min(A,B));
          }else{
          printf("%lld\n",t);
         }
     }
    return 0;
}

你可能感兴趣的:(N进制运算)