## 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, 5:45 p.m.

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

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

• commented on March 28, 2019, 9:38 p.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, 2:56 p.m.

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

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

Look for a pattern!

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

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

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

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

We are looking for the bitwise XOR.

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

• 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

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

thanks