BETA

Difficulty Level: Basic

Submissions: 3198 Accuracy:

18.2%

Closest Number
     

Given two integers n and m. The problem is to find the number closest to n and divisible by m. If there are more than one such number, then output the one having maximum absolute value. If n is completely divisible by m(not equal to 0), then output n only. Time complexity of O(1) is required.

Input:
The first line consists of an integer T i.e number of test cases. The first and only line of each test case contains two space separated integers n and m.

Output:
Print the closest number to n which is also divisible by m.

Constraints: 
1<=T<=100
-1000<=n<=1000

Example:
Input:

2
13 4
-15 6

Output:
12
-18

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Ashtputre

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.