550.Count Multiples of K up to N
Easy
Given
n and k, return how many of the numbers 1, 2, …, n are multiples of k.
This is a small example of why performancePerformanceHow much time (and memory) a program needs, especially as its input gets larger. matters. A check-every-number loop is fine for n = 20 but does a million checks for n = 10⁶ — and real programs run such code thousands of times. A little thinking turns the whole loop into a single division. Both are correct; only one scalesScalabilityHow well a solution keeps up as the input grows much larger..
Example 1:
Input: n = 20, k = 6
Output: 3
Example 2:
Input: n = 5, k = 9
Output: 0
+ 5 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ n ≤ 1000000 - ●
1 ≤ k ≤ 1000000
n =
20
k =
6