← Complete problem index

PROJECT EULER · #0539

Odd Elimination

Statement only · UnsolvedOriginal problem ↗

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:
123456789
2468
26
6

Let P(n) be the last number left starting with a list of length n.
Let S(n)=k=1nP(k).
You are given P(1)=1, P(9)=6, P(1000)=510, S(1000)=268271.

Find S(1018)mod987654321.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.