Extremely Hot Chocolate!

Today, Brian is generous and wants to offer a hot chocolate to all of his n n friends. Unfortunately, Brian has enough money only for n 1 n-1 hot chocolates, so he decided to play a game.

The game starts by placing his n n friends around a table, and numbering them from 0 to n 1 n-1 in clockwise order.

  • Person 0 starts off with an empty plastic cup.
  • Every person who directly receives the cup from another person around the table, wins a hot chocolate and leaves the game.
  • Once person p p is gone, the cup is taken by the person to the left of p p .
  • The game ends when there is only one person left, who unfortunately will not receive a hot chocolate.
  • In the first move, person 0 gives the cup to person 1.

Let us denote as L n L_n the last person in a game of n n people.

For example with 5 people the game would play out as:

0 1 2 3 4 0 2 4 2 0\rightarrow\boxed{1}\rightarrow2\rightarrow\boxed{3}\rightarrow4\rightarrow\boxed{0}\rightarrow2\rightarrow\boxed{4}\rightarrow2

So L 5 = 2 L_5=2 .

What is the digit sum of ( L 2 150 1 m o d ( 1 0 9 + 7 ) ) ? \; (L_{2^{150}-1}\mod(10^9+7)) \;\;?


Image Credit: Wikipedia .


The answer is 43.

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

Brian Riccardi
Feb 24, 2016

The idea is to construct the solution from smaller values of the table, in particular:

L n = { 0 i f n = 1 2 × L n / 2 i f n e v e n L n 1 + 2 i f n o d d L_n = \begin{cases} 0 & if \;\;n=1 \\ {2}\times{L_{n/2}} & if \;\;n\;\;even \\ L_{n-1}+2 & if\;\;n\;\;odd \end{cases}

The base case is obvious, let's see the recurrence relations:

  • if n n is even, after the first round of moves all odd numbers are gone, so remains n 2 \frac{n}{2} people; we can now re-map them from 0 0 to n 2 1 \frac{n}{2}-1 , calculate who lose and then reconstruct the initial mapping
  • otherwise we can eliminate person 1 1 and reduce the problem to n 1 n-1 people rotated counter-clockwise; like the even case we just re-map, solve and reconstruct the solution

It seems a Computer Science problem, but it is not diffcult to see a pattern in this sequence:

0 , 0 , 2 , 0 , 2 , 4 , 6 , 0 , 2 , 4 , 6 , 8 , 10 , 0,0,2,0,2,4,6,0,2,4,6,8,10, \dots

with a little bit of creativity we can build up a closed form:

L n = 2 × ( n 2 l o g 2 ( n ) ) L_n = 2\times(n - 2^{\lfloor log_2(n)\rfloor})

and prove it by induction (I leave this to the reader).

Once we have the closed-form it's easy to find the m o d mod solution: 769740172 \boxed{769740172} .

And then it's digit sum: 43 \boxed{43} .

PS: obviously there are different approaches and many of them are more efficient in the odd case!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...