Problem 126827 · easy · Level 01 Prerequisites & Setup

Round to the Nearest Step

functions · integer division · arithmetic · rounding

Write round_to(n, step) that returns the multiple of step closest to the integer n. If n is exactly halfway between two multiples, return the larger one (for negative numbers that is the one closer to zero: -25 with step 10 gives -20).

Examples

Input:  n = 47, step = 5
Output: 45
Input:  n = 45, step = 10
Output: 50
Input:  n = -25, step = 10
Output: -20

Constraints

  • -10**9 <= n <= 10**9, 1 <= step <= 10**6
  • The result must be an int.

Goals

  • Round an integer to the nearest multiple of another integer
  • Handle the halfway case deliberately
Starting Python…