Round To Nearest Multiple

Round To Nearest Multiple

Hard Computer Mathematics Integers & Divisibility 20 views
Explanation Complexity

Problem Statement

Given n and k>0, round n to nearest multiple of k (ties go up).

Input Format

Two integers n k.

Output Format

Rounded multiple.

Example

14 5
15

Constraints

k>0

Input / Output Format

Input Format
Two integers n k.
Output Format
Rounded multiple.
Constraints
k>0

Examples

Input:
14 5
Output:
15

Example Solution (Public)

Computer Mathematics
Compute down = floor(n/k)*k. up = down+k. Compare distances. If equal choose up.

Official Solution Code

Compute down = floor(n/k)*k. up = down+k. Compare distances. If equal choose up.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.