0

The outer loop runs $n$ times. The inner loop runs $\lfloor \frac{n}{i} \rfloor$ times. So it would be $O(n \cdot \lfloor \frac{n}{i} \rfloor)$. I do not know how to transform that into a proper expression involving Big Oh and n. Maybe it could be first expressed as a sum:

$\qquad\displaystyle \sum_{i=1}^n \sum_{j=i}^n \frac{n}{j}$.

for i = 1 to n:
    j = i
    while j ≤ n:
        A[j] = A[j] + 1
        j = j + i

Could you please indicate, apart from the actual running time of the algorithm, how to show the said running time?

Raphael
  • 72,336
  • 29
  • 179
  • 389

0 Answers0