#P1145. Find the Minimal Elimination Step in a Josephus Circle
Find the Minimal Elimination Step in a Josephus Circle
Find the Minimal Elimination Step in a Josephus Circle
In a classic Josephus problem, n people (numbered from 0 to n-1) stand in a circle and every m-th person is eliminated until only one person remains. In this problem, there are 2k people arranged in the circle. The first k persons (positions 0 to k-1) are "good" and the next k persons (positions k to 2k-1) are "bad". The counting starts at person 0 (the first good person).
Your task is to determine the smallest integer m such that during the elimination process, the first k people that get eliminated are all bad people. In other words, before any good person is eliminated, all k bad persons (those originally at positions k to 2k-1) must be eliminated.
The elimination process is defined as follows:
- Start with a list of persons from 0 to 2k-1.
- Let the current index be 0. In each step, count m persons (wrapping around the circle) and eliminate the person at that position.
- If the eliminated person is a good person (i.e. index < k) before all k bad persons are eliminated, then m is not acceptable.
- Continue the process until exactly k persons have been eliminated. If all these eliminated persons are bad, then m is a valid solution.
Find the smallest m that meets the above condition.
Note: All formulas are in \(\LaTeX\) format. Here, the total number of people is \(2k\), and the process stops as soon as k persons have been removed.
inputFormat
The input consists of a single integer k (\(1 \leq k \leq 50\) or as specified), representing the number of good people and the number of bad people (the total number of people is \(2k\)).
outputFormat
Output the smallest integer \(m\) such that in the elimination process all k bad persons are eliminated before any good person is eliminated.
sample
1
2