← 返回 bloomberg 的题目列表Find the Last Person in a Circular Elimination Game
类型:online_judge
There are n people standing in a circle. Start counting from any person from 1, and remove every k-th person from the circle. Repeat this process until only one person remains. Find the index of the last remaining person in the original sequence.
Input
n (1 <= n <= 10^5): The total number of people.
k (1 <= k <= 10^5): The counting interval.
Output
The index of the last remaining person, counting from 1.
Example
Example 1
Input: n = 5, k = 2 Output: 3
Example 2
Input: n = 7, k = 3 Output: 4
Note
Please implement the algorithm efficiently to ensure acceptable performance for maximum input sizes.
Example
Input
5 2