Question: 1 # Write a Program 2 3 Write a program that accepts a positive integer $N$ indicating $N$ test cases. 4 5 For each


1 # Write a Program 2 3 Write a program that accepts a positive integer $N$ indicating $N$ test cases. 4 5 For each test case, the program accepts two positive integers $M$ and $D$ in one line, and outputs the integer divisible by $D$ that is nearest to $M$. 6 7 For example, the nearest integer to $122$ that is divisible by $5$ is $120$. 8 9 If there are two equally nearest integers, the program outputs the smallest among them. 10 11 ## Input Range 12 13 *The input to this program will only come from the following range. (Your code does not need to check if the input is in this range).* 14 15- $1 \leq N \leq 10$ 16- $1 \leq M \leq 1000000$ 17 - $1 \leq D < M$ 18 19 ## Sample Run 1 20 21 22 N -> 4 23 24 Input: 25 122 5 26 Output: 27 120 28 29 Input: 30 999 131 31 Output: 32 1048 33 34 Input: 35 21 6 36 Output: 37 18 38 39 Input: 40 24 6 41 Output: 42 24 43 44 45 ## Sample Run 2 46 47 48 N -> 2 49 50 Input: 51 1 1 52 Output: 53 1 54 55 Input: 56 99 1 57 Output: 58 99 59
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
