This math problem based on something from history.
There was group of Jewish soldiers who were surrounded by the Roman army and they didn't want to get captured, so they decided to come up with a system to avoid getting captured or suicide. So they'd sit in a circle, and the first man would kill the guy to the left of him. The next remaining living person would kill the next remaining living person with their sword. They'd go around like this, till there's only one person left. And the last person would have to suicide, rather than captured.
In the story, Josephus preferred captured than suicide but he worried that if he said this, the other soldiers would turn on him. So he wanted to figure out. Where should he sit within the circle in order to be the last man living and then he would surrender, rather than kill him self. That was the problem.
This program calculates where Josephus should be sit in the circle
Sources
- History (https://en.wikipedia.org/wiki/Josephus_problem)
- Mechanism and algorithm (https://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/)