X and K
InterviewTime limit2sMemory limit128 MB
Given X and K, find the K-th smallest positive integer Y such that X+Y equals X OR Y, which requires placing K's bits into the zero-bit positions of X.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Math, Implementation
- Solved
- No attempts yet
Problem
You are given two positive integers X and K. List all positive integers Y that satisfy the following equation in increasing order, and find the K-th smallest such Y.
X + Y = X | Y
Here, | denotes the bitwise OR operation.
Input
The first line contains two positive integers X and K, separated by a space.
Each of X and K is at most 2,000,000,000.
Output
Print the K-th smallest positive integer Y satisfying X + Y = X | Y.
The answer may be greater than 2^31 - 1.