Today, Brian is generous and wants to offer a hot chocolate to all of his friends. Unfortunately, Brian has enough money only for hot chocolates, so he decided to play a game.
The game starts by placing his friends around a table, and numbering them from 0 to in clockwise order.
Let us denote as the last person in a game of people.
For example with 5 people the game would play out as:
So .
What is the digit sum of
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.
The idea is to construct the solution from smaller values of the table, in particular:
L n = ⎩ ⎪ ⎨ ⎪ ⎧ 0 2 × L n / 2 L n − 1 + 2 i f n = 1 i f n e v e n i f n o d d
The base case is obvious, let's see the recurrence relations:
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 , 1 0 , …
with a little bit of creativity we can build up a closed form:
L n = 2 × ( n − 2 ⌊ l o g 2 ( n ) ⌋ )
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 solution: 7 6 9 7 4 0 1 7 2 .
And then it's digit sum: 4 3 .
PS: obviously there are different approaches and many of them are more efficient in the odd case!