P539
projecteuler.net

Odd Elimination

ℹ️Published on Sunday, 20th December 2015, 04:00 am; Solved by 919;
Difficulty rating: 35%

Start from an ordered list of all integers from $1$ to $n$. Going from left to right, remove the first number and every other number afterward until the end of the list. Repeat the procedure from right to left, removing the right most number and every other number from the numbers left. Continue removing every other numbers, alternating left to right and right to left, until a single number remains.

Starting with $n = 9$, we have:
$\underline 1\,2\,\underline 3\,4\,\underline 5\,6\,\underline 7\,8\,\underline 9$
$2\,\underline 4\,6\,\underline 8$
$\underline 2\,6$
$6$

Let $P(n)$ be the last number left starting with a list of length $n$.
Let $\displaystyle S(n) = \sum_{k=1}^n P(k)$.
You are given $P(1)=1$, $P(9) = 6$, $P(1000)=510$, $S(1000)=268271$.

Find $S(10^{18}) \bmod 987654321$.



Soluzione

Last modified: May 01, 2025. Website built with Franklin.jl and the lovely Julia programming language.