题目描述
Given two numbers X and Y, and a range [L, R] where 1 <= L <= R <= 31. Find the set bits of Y in range [L, R] and set these bits in X also. Return this modified X.
Example 1:
Input:
X = 44, Y = 3
L = 1, R = 5
Output: 47
Explaination: Binary represenation of 44 and 3 is 101100 and 11. So in the range 1 to 5 there are two set bits. If those are set in 44 it will become 101111 which is 47.
Example 2:
Input:
X = 16, Y = 2
L = 1, R = 3
Output: 18
Explaination: Binary represenation of 16 and 2 is 10000 and 10. If the mentioned conditions are applied then 16 will become 10010 which is 18.
Your Task:
You do not need to read input or print anything. Your task is to complete the function setSetBit() which takes the numbers X, Y, L and R as input parameters and returns the modified value of X.
Expected Time Complexity: O(R - L)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ X, Y ≤ 10^{9}
1 ≤ L ≤ R ≤ 32
输入格式
见题面
输出格式
见题面