Pergunta de entrevista da empresa Bloomberg

Josephus problem. Not easy to get the trick if see it for the first time.