Last Updated: 28 Apr, 2021

Vaccination Drive

Easy
Asked in company
Google inc

Problem statement

The Indian government recently launched the world's largest vaccination drive for COVID-19. Dr Ritesh has been appointed as a nodal officer for vaccinating a locality. There are ‘N’ houses numbers from 1 to ‘N’ in that locality. Dr Ritesh will visit each house one by one and vaccinate all the people in the house. He has already covered ‘K’ number of houses. Since ‘N’ is a very large number, ‘L’ bits are required to represent the number. You are supposed to help Dr Ritesh and find the maximum possible number of houses that are yet to be covered under the vaccination drive.

Input Format :

The first line contains an integer ‘T’ denoting the number of test cases. Then each test case follows.

The first input line of each test case contains two space-separated integers ‘K’ and ‘L’ as described in the problem.

Output Format :

For each test case, print the maximum possible number of houses that are yet to be covered under the vaccination drive.

The output of each test case will be printed in a separate line.

Note:

You are not required to print the expected output, it has already been taken care of. Just implement the function.

Constraints :

1 <= T <= 50
1 <= ‘K’ <= N
1 <= ‘L’ <= 30

Where ‘T’ is the number of test cases, ‘K’, ‘N’ and ‘L’ are described in the problem statement.

Time limit: 1 sec

Approaches

01 Approach

We know that a maximum of 2^L numbers can be represented using ‘L’ bits. Therefore a maximum possible value for ‘N’ will be 2^L. Hence, the maximum possible number of remaining houses will be 2^L - K.


We can use the inbuilt pow() function.

02 Approach

We can also use the left shift operator for calculating 2 ^ L.

 

Answer = (1 << L) - K