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; }
相关文章推荐
- Sicily 11598 XOR
- soj 11598. XOR
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor(xor运算应用)
- codeforce 862C Mahmoud and Ehab and the xor(构造)
- XOR tricks for RAID data protection
- 【第400篇题解纪念2016年10月28日】【28.10%】【codeforces 617E】XOR and Favorite Number
- 单链表 -> 双向链表 [XorList]
- Wannafly挑战赛1 B.Xorto 两区间异或和
- Sicily 1796. Max's kingdom
- Wannafly挑战赛1 B Xorto 前缀和
- Sicily 1031 Campus(Dijkstra[邻接表+优先队列优化])
- Sicily 1155. Can I Post the letter
- Sicily 1001 Alphacode
- POJ 3764 The xor-longest Path 01字典树+dfs
- Sicily 1050. Numbers & Letters
- SGU 275 - To xor or not to xor 按位贪心 线性基
- POJ3764 The xor-longest Path
- To xor or not to xor SGU - 275 gauss
- Sicily 1795 Table tennis
- Educational Codeforces Round 32 G. Xor-MST 01字典树+二叉树 (板子