A - ^&^

Bit operation is a common computing method in computer science ,Now we have two positive integers C is equal to 1. 

If the value of the expression is 0 when C=0, please print 1. 

Input

The input file contains 1≤A,B<232)OutputFor each test case,you should output the answer and a line for each answer. 
Sample Input

1
3 5

Sample Output

1


   由题意:找到最小C,使(A xor C)&(B xor C)最小。根据分配律,原式=(A&B) xor C;
  A,B已知,则(A&B)为固定值,又根据xor(异或)知识:同为0,异为1,则要想使原式最小,C要==(A&B)才行,因为两个数异或运算,如果两个数相同,同为0,结果最小。
所以C=(A&B)。
  又根据题意最后一句:If the value of the expression is 0 when C=0, please print 1. 
  有代码:
    
#include<iostream>
typedef long long ll;
using namespace std;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        if((a&b)==0)
            printf("1\n");
        else
            printf("%lld\n",a&b);
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案