14-2 Josephus permutation
We define the Josephus problem as follows. Suppose that people form a circle and that we are given a positive integer . Beginning with a designated first person, we proceed around the circle, removing every th person. After each person is removed, counting continues around the circle that remains. This process continues until we have removed all people. The order in which the people are removed from the circle defines the -Josephus permutation of the integers . For example, the -Josephus permutation is .
a. Suppose that is a constant. Describe an -time algorithm that, given an integer , outputs the -Josephus permutation.
b. Suppose that is not a constant. Describe an -time algorithm that, given integers and , outputs the -Josephus permutation.
(Removed)