XOR

View as PDF

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

Problem type

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

Input Specification

The first line of input is the integer , which is the number of test cases .
lines follow, with each line containing two integers and .

Output Specification

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

Sample Input

5
3 10
5 5
13 42
666 1337
1234567 89101112

Output for Sample Input

8
5
39
0
89998783

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

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

• 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.

• commented on March 29, 2019, 1:38 a.m.

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

• 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?

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

Look for a pattern!

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

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

• 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?

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

We are looking for the bitwise XOR.

• 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...

• 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

• commented on Dec. 5, 2014, 6:12 p.m.

thanks