Find the safe position
Submissions: 381   Accuracy:

28.84%

  Difficulty: Basic   Marks: 1

There was a group of Jewish soldiers who were surrounded by Roman Army in a circular fence. They decided not to get captured by the brutal Roman Army. So, they made a plan.
They planned to kill each other. The soldier would kill the fellow soldier next to him on left. They would do so till only one soldier is left and in the last the remained soldier would kill themselves. But there was a problem, soldier A didn’t want to die he want to stay alive so he wanted to stand a position where he could stand till last. After all his fellow soldiers died he would simple surrender himself rather then killing himself. So, what we have to do in this problem is that we have to find the safe_position of soldier A.


Input : 
The first line of input contains an integer T denoting the Test cases. Then T test cases follow. Each test case contains an integer  N denoting the no. of soldiers


Output : 
For each test case in a new line print the safe position for soldier A.


Constraints :
1 ≤ T ≤ 50
1 ≤ N ≤ 105


Input : 
2
10
3
Output : 
5
3

Explanation  :
For first test case
1 kills 2 : 3 kills 4 : 5 kills 6 : 7 kills 8 : 9 kills 10
Now 1 kills 3 : 5 kills 7 : 9 kills 1 
Now 5 kills 9 

Safe_Position  : 5

For second test case:
1 kills 2 
3 kills 1

Safe_Position  : 3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Mohit Gupta...OMG :)
Author: Mohit Gupta 4


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.