Closest Number
Submissions: 24766   Accuracy:

26.68%

  Difficulty: Basic   Marks: 1
Associated Course(s):   Interview Preparation
     

Given non-zero 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.

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

Output:
For each testcase, in a new line, print the closest number to N which is also divisible by M.

Constraints: 
1 <= T <= 100
-1000 <= N, M <= 1000

Example:
Input:

2
13 4
-15 6
Output:
12
-18

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

Author: saksham0751


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

to report an issue on this page.