Xtreme 10.0 - Flower Games

Every girl like flowers. No, I’m not gonna talk about that. Instead we are going to play a game with flowers.
Problem
Joy and her friends found a flower with N petals and want to play a modified version of the He loves me… he loves me not game. The girls number the petals with numbers from 1 to N in the clockwise direction. They will traverse the petals in circular order starting with 1, then 2, …, then N, then 1… At the first petal, they will shout “He loves me”, at the second “He loves me not” and tear it, at the third “He loves me”, at the fourth “He loves me not” and tear it. The girls will continue the game until there is only one petal left. The task is to identify the number of the last petal.
e.g.: With 6 petals, one would skip 1, tear 2, skip 3, tear 4, skip 5, tear 6, skip 1, tear 3, skip 5, tear 1, and then only 5 is left.
Original problem here.
Input Format
The input begins with an integer T, giving the number of test cases in the input.
Each test-case consists of an integer N, on a line by itself.
Constraints
1 <= T <= 100000
1 <= N < 2⁶³
Output Format
The location of the last petal, on a line by itself.

This is where you stop if you wanna solve it by yourself. :-)
Method to Solve
Let’s just solve the game for flowers with 1 petal to flowers with 16 petals. In the following table, the first value is #petals and the second value is #last petal.
| 1 | 1 |
| 2 | 1 |
| 3 | 3 |
| 4 | 1 |
| 5 | 3 |
| 6 | 5 |
| 7 | 7 |
| 8 | 1 |
| 9 | 3 |
| 10 | 5 |
| 11 | 7 |
| 12 | 9 |
| 13 | 11 |
| 14 | 13 |
| 15 | 15 |
| 16 | 1 |
| . | . |
| . | . |
| . | . |Do you see how the answer is changing? It is following the sequence of odd numbers but keeps restarting when the #petals is a factor of 2.
Given a flower with n #petals, #last petal can be found if we know the index of the sequence 1, 3, 5, … that flower belongs. Since we know the pattern now, that index can be easily calculated as below.
Note: This is a Python3 code sample.
The moral of the story is that to solve some problems in our life, you just need to understand the pattern of answers rather than finding just the answer. ;-)
Thanks for reading! I am open to your ideas and feedback.
