Who survives at the end ?

There are n n people standing in a circle. Each person is numbered in order from 1 1 to n n . Person 1 1 has a sword. He kills the next person( i.e. Person 2) and gives the sword to the next( i.e. Person 3). All people do the same until only 1 survives.

if n = 10052020 n = 10052020 , which Person survives at the end. Enter that Person number as your answer.


The answer is 3326825.

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.

1 solution

We see that when n n is even the sword goes back to the Person 1 after 1 iteration When n n is odd the sword goes to the Person n after 1 iteration. In general, at any stage, if number of person is n n and sword is with Person p p then if n n is even, sword will remain with Person p p after 1 iteration and number of person will reduce to n 2 \large\frac{n}{2} and if n n is odd, sword will goes to Person p 1 p-1 after 1 iteration and number of person reduces to n + 1 2 \large\frac{n+1}{2} .

On this basis, we conclude that at any stage, if the number of persons is a power of 2 and sword is with Person p p , then at the end Person p p will survive.

Solving in general,

If n n are persons are there, we have to find the value of integral k k such that 2 k n < 2 k + 1 2^k \leq n < 2^{k+1} . Now we have to find r r such that n = 2 k + r n = 2^k + r where r r will range from 0 to 2 k 1 2^k - 1

r = n 2 k 2 r = 2 n 2 k + 1 2 r = n + n 2 k + 1 n 1 [ n < 2 k + 1 n 2 k + 1 < 0 n 2 k + 1 1 ] \hspace{15pt} r = n - 2^k\newline \Rightarrow 2r = 2n - 2^{k+1} \newline\Rightarrow 2r = n + n - 2^{k+1} \leq n-1\hspace{20pt} [\because n < 2^{k+1} \Rightarrow n - 2^{k+1} < 0 \Rightarrow n - 2^{k+1} \leq -1]

This last equation assures that it is possible to kill r r persons in 1 s t 1^{st} iteration starting form Person 1 to get the number of person as 2 k 2^k that is the power of 2.

Since Person 1 kills Person 2, Person 3 kills Person 4 and so on, so r t h r^{th} person to die is the Person 2 r 2r who is kiiled by the Person 2 r 1 2r - 1 and this Person after killing Person 2 r 2r gives the sword to Person 2 r + 1 [ 2r + 1\hspace{20pt} [ Person 2 r + 1 2r + 1 exists because 2 r + 1 n ] 2r + 1 \leq n]

Now, sword is with Person 2 r + 1 2r + 1 and there are 2 k 2^k persons left. Hence at the end Person 2 r + 1 2r + 1 will survive.

Now finding the value of r r in terms of n n

We have,

2 k n < 2 k + 1 k log 2 n < k + 1 k = log 2 n \hspace{13pt} 2^k \leq n < 2^{k+1} \newline\Rightarrow k \leq \text{log}_2 n < k + 1\newline \Rightarrow k = \lfloor \text{log}_2 n \rfloor

Now r = n 2 log 2 n r = n - 2^{\lfloor \text{log}_2 n \rfloor}

Hence at the end, Person 2 ( n 2 log 2 n ) + 1 2(n - 2^{\lfloor \text{log}_2 n \rfloor}) + 1 will survive.

In the question, n n is given 10052020 10052020 .

log 2 n = log 2 10052020 = 23.261 log 2 n = 23 2 log 2 n = 2 23 = 8388608 n 2 log 2 n = 10052020 8388608 = 1663412 2 ( n 2 log 2 n ) = 2 1663412 = 3326824 2 ( n 2 log 2 n ) + 1 = 3326824 + 1 = 3326825 \Rightarrow \text{log}_2 n = \text{log}_2 10052020 = 23.261 \newline \Rightarrow \lfloor \text{log}_2 n \rfloor = 23 \newline \Rightarrow 2^{\lfloor \text{log}_2 n \rfloor} = 2^{23} = 8388608 \newline \Rightarrow n - 2^{\lfloor \text{log}_2 n \rfloor} = 10052020 - 8388608 = 1663412 \newline \Rightarrow 2(n - 2^{\lfloor \text{log}_2 n \rfloor}) = 2\cdot 1663412 = 3326824 \newline \Rightarrow 2(n - 2^{\lfloor \text{log}_2 n \rfloor}) + 1 = 3326824 + 1 = 3326825

Hence at the end Person 3326825 will survive.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...