Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <stack>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- string to_binary(long long x) {
- string r = "";
- while(x) {
- r += (x % 2) + '0';
- x /= 2;
- }
- reverse(r.begin(), r.end());
- return r;
- }
- int main() {
- ll numa, numb;
- int n;
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> numa >> numb;
- string a = to_binary(numa);
- string b = to_binary(numb);
- if(a.size() != b.size()) {
- cout << 0 << endl;
- continue;
- }
- string tmp = "";
- for(int i = 0; i < a.size(); i++) {
- if(a[i] == b[i]) {
- tmp += a[i];
- }
- else {
- break;
- }
- }
- while(tmp.size() < a.size()) {
- tmp += "0";
- }
- long long result = 0;
- long long stepen = (int) a.size() - 1;
- for(int j = 0; j < tmp.size(); j++) {
- if(tmp[j] == '1') {
- result |= (1LL << stepen);
- }
- stepen--;
- }
- cout << result << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement