Josephus problem solution with o(n)
1.Description
People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.
2.Introduction
We have seen this kind of problems before. You can stimulate the whole process to get the answer you want. But its time cost is large, which holds a m*n complexity. This method can be accepted when n and m are accepted small, but fail to handle those situations when n or m is quite large. Thus, today let’s introduce a new method with a complexit