Explanation

559.Count Iterations of a Stepping Loop

Easy
For the loop for (i = 0; i < n; i += k), return how many times its body runs. Finding a loop's complexity starts with counting its iterationsIterationOne pass through a loop body.. Here i starts at 0 and jumps by k, so the body runs about n / k times — exactly ⌈n / k⌉. When k is a fixed constant this is O(n); the step size changes the count by a constant factor, not the growth rate.

Example 1:

Input: n = 10, k = 3

Output: 4

Example 2:

Input: n = 0, k = 5

Output: 0

+ 5 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 1000000
  • ●1 ≤ k ≤ 1000000

n =

10

k =

3