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

People 1 to 10 stand in a circle. Starting from person 1, every second person is eliminated until one remains. Who survives?

  1. A. 5
  2. B. 6
  3. C. 10
  4. D. 9

Correct answer: A. 5

For k = 2 the Josephus survivor is 2 times the number of people minus a power of two, here 2 * (10 - 8) + 1 = 5 when using the closed form. The recurrence gives the same 1-based answer.

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

Exams that ask this topic