0
点赞
收藏
分享

微信扫一扫

ACdream 1020 The Game about KILL


Description



Teacher HU and his 40 students were trapped by the brigands. To show their power, the head of the brigands want to select one people to kill.

Teacher HU and his 40 students will stand in a circle, and every second person would leave, and the last people in the circle would be killed.

For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 will be killed.

To make his students alive, teacher HU calculated the position to be the last man standing, and sacrifice himself.

Now we consider a more common condition, if teacher HU has N - 1 students, which place should he stand to be the last person.


Input



There are multiple test cases. 
Each test case only contains an integer  N. (1 ≤ N ≤ 1,000,000,000)


Output



For each test case, output an integer indicating which place should teacher HU stand.


Sample Input



2 3


Sample Output



1

3


打表这规律,可以看出答案的分布情况是

1 3 1 3 5 7 1 3 5 7 9 11 13 15 .....

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define fi first
#define se second
#define mp(i,j) make_pair(i,j)
#define pii pair<int,int>
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int read()
{
char ch = getchar();
while (ch<'0' || ch>'9') ch = getchar();
int x = ch - '0';
while ((ch = getchar()) >= '0'&&ch <= '9') x = x * 10 + ch - '0';
return x;
}
int T, n, x, y;
int f[N];

int main()
{
/*rep(i, 1, 100)
{
queue<int> p;
rep(j, 1, i) p.push(j);
while (p.size() > 1)
{
int q = p.front(); p.pop(); p.pop(); p.push(q);
}
printf("%d %d\n", i, p.front());
}*/
while (scanf("%d",&n)!=EOF)
{
for (int i = 0; n > 1 << i; i++) n -= 1 << i;
printf("%d\n", n * 2 - 1);
}
return 0;
}



举报

相关推荐

about

About Pycharm

1020 月饼

About MATLAB

Talking about Health

0 条评论