Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B

What is the value of the sum of floor(20 / i) for i = 1 to 20?

  1. A. 66
  2. B. 65
  3. C. 72
  4. D. 60

Correct answer: A. 66

Σ floor(20/i) also equals the total number of divisors of 1..20, which is 66; floor values take only O(√n) distinct values, so blocks can be summed. Stopping at i = 19 gives 65, skipping the floor gives 20·H₂₀ ≈ 72, and the n ln n estimate gives 60.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic