Data Structures & AlgorithmsHardGATE CS · competitive programming

How many times does the body of for (i = 2; i * i ≤ n; i++) run for n = 10⁶?

  1. A. 1000
  2. B. 998
  3. C. 500
  4. D. 999

Correct answer: D. 999

i * i ≤ 10⁶ holds for i ≤ 1000, and i starts at 2, so i = 2..1000 gives 999 runs. Starting at 1 would give 1000.

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

Exams that ask this topic