Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B
What is the value of the sum of floor(20 / i) for i = 1 to 20?
- A. 66
- B. 65
- C. 72
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A bubble sort performs left-to-right passes, swapping adjacent elements that are out of order, and stops after the first pass in which no…
- Six people stand in a circle numbered 1 to 6. Starting from person 1, every 4th person (counting the start as 1) is removed until one…
- How many contiguous subarrays of [1, 3, 2, 4, 6, 5] have (maximum minus minimum) at most 2?
- How many non-empty contiguous subarrays of [2, -1, -1, 3, -2, 1, 1, -2, 0] have a sum of exactly 0?
- What is the maximum sum over all non-empty contiguous subarrays of [3, -8, 4, -1, 2, -6, 5, 1, -7, 4]?
- For the circular array [5, -3, 4, -6, 2, 3, -1, 4], what is the maximum sum of a non-empty subarray when the array is treated as circular…