Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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

Input Specification

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

Output Specification

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

Sample Input

5
3 10
5 5
13 42
666 1337
1234567 89101112

Output for Sample Input

8
5
39
0
89998783

Comments


  • -1
    noYou  commented on June 3, 2020, 5:45 p.m.

    My wrong submission passed. Doesn't even pass sample, more test cases are probably needed.


  • 2
    sankeeth_ganeswaran  commented on March 28, 2019, 8:52 p.m.

    I'm a bit confused, how is the XOR of 5 and 5 equal to 5? I thought it was 0.


    • 3
      Kirito  commented on March 28, 2019, 9:38 p.m.

      It's asking you for the XOR of all numbers in the range [S, F]. 5 is the only number in the range [5, 5], so the answer is 5.


  • -5
    Anix55  commented on Dec. 5, 2015, 2:56 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 4
      Xyene  commented on Dec. 5, 2015, 3:48 p.m.

      Look for a pattern!


      • -4
        poinzetta  commented on Feb. 19, 2016, 6:06 p.m.

        So there IS a pattern! ahh.....


  • 0
    Yuting9  commented on Dec. 4, 2014, 5:06 p.m.

    How do you get an XOR of a multi digit number? Isn't it only for True and False?


    • 3
      FatalEagle  commented on Dec. 4, 2014, 6:32 p.m.

      We are looking for the bitwise XOR.


      • 0
        Yuting9  commented on Dec. 5, 2014, 9:47 a.m.

        When I do that, 3 and 10 give me 9, and 5 and 5 give 0...


        • 1
          awaykened  commented on Dec. 5, 2014, 10:17 a.m.

          you are misunderstanding the problem it asks for the xor of all numbers between s and f, so for the example of 3 and 10 it would be 3 XOR 4 XOR... XOR 10


          • 0
            Yuting9  commented on Dec. 5, 2014, 1:12 p.m.

            thanks