Answered step by step
Verified Expert Solution
Question
1 Approved Answer
n people decide to elect a leader by arranging themselves in a circle and eliminating every m-th person around the circle, closing ranks as
n people decide to elect a leader by arranging themselves in a circle and eliminating every m-th person around the circle, closing ranks as each person drops out. The problem is to find out which person will be the last one remaining. This picture illustrates the problem for n = 9 and m = 5. In this particular case, the person in position 8 is the last person standing and will be elected as the leader. The initial circle of 9 people. Counting starts (counter-clockwise) from person 1 and the fifth person is eliminated. The fifth person (counter-clockwise) from Person # 6 is Person #1. So now Person #1 gets eliminated. Person 5 gets eliminated and the ranks close. Eight people remain in the circle. Counting now starts again from Person #6 Bay until a single person remains. That person is now the winner! Counting continues as usual, eliminating the fifth person at each round. You wish to be the leader of this group of n people. Find the position that you need to occupy in order to be elected leader. circle Test your code for different values of m and n. Here are the results you should get for different values of m and n: o When n = 7 and m = 2, the leader should be 7 (and people are eliminated in this order: 2, 4, 6, 1, 5, 3. Do this by-hand also to ensure this answer is correct). o When n = 9 and m = 5, the leader should be 8 (this is the same as the example shown in the picture above). o When n = 1 000 000 and m = 10, the leader should be the 630 538-th person in the circle.
Step by Step Solution
★★★★★
3.41 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
To determine the position in the circle that you need to occupy in order to be elected leader you ca...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started