Problem 126827 · easy · Phase 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.

Examples

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

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…