New update is available. Click here to update.

Set K Bits

Posted: 7 Dec, 2020
Difficulty: Easy

PROBLEM STATEMENT

Try Problem

Given a number ‘N’. You have to set bits from 0 to Kth position.

Example: If the Given number is 37 (100101) and ‘K’ = 4, then we need to set the 0,1,2,3 bits and thus after the Kth bit set our answer would be 47 (101111).

Input Format:
The first line contains a single integer ‘T’ representing the number of test cases. 

The first line of each test case will contain two integers ‘N’ and ‘K’ where ‘N’ denotes the number whose 0 to ‘K’th bits have to be set and ‘K’ indicates the limit upto where from 0th bit, the bits have to be set.
Output Format:
For each test case, print the number after 0 to Kth bits are set.

Output for every test case will be printed in a separate line.
Note:
You don’t need to print anything; It has already been taken care of.
Follow Up:
 Can you solve this using O(1) time and space complexity? 
Constraints:
1 <= T <= 10
-10^9 <= N <= 10^9
1 <= K <= 31


Time limit: 1 sec