Flavius Josephus was a famous historian of the first century. During the Jewish-Roman war, he was among a band of 41 Jewish rebels trapped in a cave by the Romans. Preferring suicide to capture, the rebels decided to form a circle and to kill every third remaining person until no one was left. But Josephus, along with an unindicted conspirator, wanted none of this suicide nonsense and therefore quickly calculated where he and his friend should stand in the circle so that they can survive.
We will start with people numbered to around a circle, and we'll eliminate every second remaining person until only one survives (the main problem is to find the survivor's number).
Let be the survivor's number, and as an example take , then the order of elimination would be 2,4,6,8,10,3,7,9,1. So, number 5 survives. Therefore, .
It is easy to notice that is always an odd number because the first trip around the circle would eliminate all the even numbers. Also, if is even number then we will come at the same situation except this time there are only half as many people and their numbers have changed.
Now let us take another case in which for some positive integral value of . In this case the person with number survives in the last always or .
Now if we take a value which may not be equal to a perfect power of , then
where and is a non-negative integer.
Now we just need to count till number of people are executed and then next person will be the one who will survive the deadly procedure.
Also, notice that if you want to find the number of person who was executed in the process, the number is ; if you want to find the number of person who was executed in the process, the number is , and so on. In general the person executed in the process has number is . (Note that this generalization is only valid when , in our case its true as .)
The person standing next with number will have number .