Timer is Running

Closest Number
Submissions: 43020   Accuracy:


  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.

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.

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

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


13 4
-15 6

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

Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

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

to report an issue on this page.