Advertisement
banovski

The closest multiple

Nov 23rd, 2022
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | Source Code | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. def multiple(number, factor):
  4.     if number == 0:
  5.         return factor
  6.     if factor == 0:
  7.         return 0
  8.     if number == factor:
  9.         return number
  10.     if number < factor:
  11.         return factor
  12.     if number > factor:
  13.         return (number + factor - 1) // factor * factor
  14.  
  15. # [multiple(i, j) for i in range(1000) for j in range(1000)]
  16. # 1000004 function calls in 0.965 seconds
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement