


Let N = 8 and M = 3
The numbers divisible by 3 are 3, 6, 9, …
From these numbers 9 is closest to 8. Thus, the answer is 9.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of each test case contains two integers N and M.
For each test case, return an integer closest to N and divisible by M.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^5
-10^9 <= N <= 10^9
1 <= M <= 10^9
Time limit: 1 sec
The brute force approach is to loop over the number closest to N and find the one which is divisible by M.
The optimal approach is to find two closest numbers to N which are divisible by M and return the one which is closest to N.
We will find two number:
And return the one which is closest to N and if both are equally close to N then return num1 as it is smaller than num2.