您的位置:首页 > 其它

Sicily 11598. XOR

2015-03-17 16:04 253 查看


11598. XOR


Constraints

Time Limit: 1 secs, Memory Limit: 256 MB


Description

Given two integers S and F, what is the XOR (exclusive-or) of all numbers between Sand F (inclusive)?


Input

The first line of input is the integer T, which is the number of test cases (1 ≤ T ≤ 1000). T lines follow, with each line containing two integers S and F (1 ≤ S ≤ F ≤ 1 000 000 000).


Output

For each test case, output the (decimal) value of the XOR of all numbers between Sand F, inclusive.


Sample Input


5
3 10
5 5
13 42
666 1337
1234567 89101112



Sample Output


8
5
39
0
89998783



Problem Source

2014年每周一赛第八场

// Problem#: 11598
// Submission#: 3378103
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string.h>
#include <math.h>
using namespace std;

inline long long XOR_from1(long long n) {
    if (n % 4 == 0) return n;
    if (n % 4 == 1) return 1;
    if (n % 4 == 2) return n + 1;
    if (n % 4 == 3) return 0;
}

int main() {

    std::ios::sync_with_stdio(false);

    int caseNum;
    cin >> caseNum;

    while (caseNum--) {
        long long a, b;
        cin >> a >> b;
        cout << (XOR_from1(b) ^ XOR_from1(a - 1)) << endl;
        
    }

    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: