#K43917. Last Remaining Person: A Josephus Problem Variation
Last Remaining Person: A Josephus Problem Variation
Last Remaining Person: A Josephus Problem Variation
You are given n people numbered from 1 to n arranged in a circle and a positive integer k. Starting from the first person, every k-th person is eliminated from the circle. The process is repeated with the remaining people until only one person remains.
The elimination index is updated using the formula:
$$ index = (index + k - 1) \mod \text{current_size} $$
Your task is to determine the 1-based position of the last remaining person.
inputFormat
The input consists of a single line containing two integers n and k separated by space.
Constraints:
- 1 ≤ n ≤ 105 (depending on the problem setting)
- 1 ≤ k ≤ 105
outputFormat
Output the 1-based index of the last remaining person.
## sample5 2
3