@pkuzw Actually you can refer to @storypku 's answer on the 1st floor. It's called mirroring. Given a sequence 1, 2, 3,...N, first we can easily know that 1 and N are mirrored by the middle of this sequence, and it holds for (2, N-1), (3, N-2) and so on. Sum of them are all N+1.

Then we come to the problem, suppose we have two rules: (1) the first elimination starts from the left side; (2) the first elimination starts from the right side. We follow the same elimination rules it's just the starting point is mirrored by the center. So we have:

lastRemaining(n) + EliminateFromRightFirst(n) = n + 1;

<=> lastRemaining(n/2) + EliminateFromRightFirst(n/2) = n/2 + 1;

<=> EliminateFromRightFirst(n/2) = 1 + n/2 - lastRemaining(n/2);

For the original sequence 1,2,3,...,n, after first elimination from left side, we have a new sequence 2,4,6,...,(n-1 or n). The new sequence consists of even numbers. Then actually it is 2 * (1, 2, 3, ..., n/2), in which the elimination for the (1, 2, 3, ... n/2) now starts from the right side. It is exactly EliminateFromRightFirst(n/2).