Submit solution

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

Problem type

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


  • 2
    noYou  commented on June 3, 2020, 9:45 p.m.

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


  • 2
    sankeeth_ganeswaran  commented on March 29, 2019, 12:52 a.m.

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


    • 6
      Kirito  commented on March 29, 2019, 1:38 a.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.


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

    TLEEEEEE ARGGGH something tells me i have to do more than just the XOR bitewise operator (^). do i?


    • 6
      Xyene  commented on Dec. 5, 2015, 8:48 p.m.

      Look for a pattern!


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

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


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

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


    • 5
      FatalEagle  commented on Dec. 4, 2014, 11:32 p.m. edited

      We are looking for the bitwise XOR.


      • 0
        Yuting9  commented on Dec. 5, 2014, 2:47 p.m.

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


        • 2
          awaykened  commented on Dec. 5, 2014, 3:17 p.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, 6:12 p.m.

            thanks