Eons from today, the dragon, fed up with the human race, rises from the scorching depths of the earth. Unparalleled in intelligence and strength, she knows nothing can oppose her. She descends on the last city of earth and summons its
residents. She then thunders:
"Every one of you, brand your skin with a different number from to . Then stand in a circle in ascending order of your numbers. I will start counting from number and devour every person. I will keep doing this, till there is just one of you left. And that person will be spared."
The people recognized the end, the numbers were permanent, branded with the fire of the dragon herself. They decide to assign numbers through a lottery. The mayor, being the world's last remaining mathematician, rigs the lottery, and ensures that he gets the number that would guarantee his survival.
On the fateful day, the dragon appears. She starts counting. And when she reaches the person, she snatches him up with her powerful claws and puts him in a nearby cage. The people are confused, then they realize that the dragon is putting all her food in the cage. One-by-one each person is picked up and put into the cage. In the end, the mayor remains. The dragon gives him a twisted grin, and as soon as the truth dawns on him, she snaps him up.
Everyone was terrified. The dragon had not kept her word. As they remained petrified in their fear, the dragon roared:
"The rules have changed! Now all of you come stand in a circle again, in ascending order of the number on your skin. We will then continue. I will start counting from the lowest number and put every person in the cage. The person who will remain after the rest of you are in the cage will be eaten. You will then be let out of the cage, and we will repeat this, till only one of you is left"
The people comply. Many hours later, the dragon leaves. One last person remains. Light catches his hand, revealing the number which was etched upon his skin. What is this number?
Note:
As an example, consider the case when there are people and the dragon puts every person in the cage:
: 2 in cage,4 in cage,1 in cage,5 in cage, 3 dies
: 2 in cage,5 in cage,4 in cage, 1 dies
: 4 in cage, 2 in cage, 5 dies
:4 in cage, 2 dies
survives.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Here is my solution in C++