Oh no, XOR again?
InterviewTime limit1sMemory limit512 MB
Count the integers x from A to B inclusive where x XOR N has exactly K ones in its binary form.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Another XOR problem came up again, and it is as tedious as ever!
You are given integers , , , and . Among the integers from to inclusive, count how many of them, when XORed with , have exactly ones in their binary representation.
Input
The first line contains , , , and , in that order, separated by spaces.
Output
Print the answer.
Constraints
Hint
Bitwise XOR is an operation that can be applied to two non-negative integers. For non-negative integers and , write each in binary, then for each bit position put 0 if the two bits are equal and 1 if they differ. The result is .
For example, take and . In binary, they are and . The first and second bits from the right are equal, so they become 0. The third and fourth bits differ, so they become 1. Therefore is .