Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

What is the smallest positive integer n such that 1 + 2 + ... + n is at least 500?

  1. A. 32
  2. B. 33
  3. C. 23
  4. D. 31

Correct answer: A. 32

Binary search on n with the closed form n(n+1)/2 finds the threshold: n = 31 gives 496, which is short, and n = 32 gives 528. Using n squared instead gives a different threshold.

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

Exams that ask this topic