Ankit_132

B

Jun 6th, 2024
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.    int t;
  6.    cin>>t;
  7.    while (t--){
  8.         long long x,y;
  9.         cin>>x>>y;
  10.         vector<long long> v1,v2;
  11.         do {
  12.             v1.push_back(x%2);
  13.             x/=2;
  14.         } while (x);
  15.        
  16.         do {
  17.             v2.push_back(y%2);
  18.             y/=2;
  19.         } while(y);
  20.        
  21.         while (v1.size()<v2.size()) v1.push_back(0);
  22.         while (v1.size()>v2.size()) v2.push_back(0);
  23.        
  24.         long long res=1;
  25.         for (int i=0; i<v1.size(); i++)
  26.         if (v1[i]==v2[i])
  27.             res=(long long)res*2;
  28.         else
  29.             break;
  30.        
  31.         cout<<res<<"\n";
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment