Problem 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
题意:给出一个人数n,问以间隔2来去除,最后一个留下的是编号几。
归律:1:1  2:1  3:3  4:1  5:3  6:5  7:5  8:1  9:3  10:5  .......  能够看出输出的都是奇数,并且从2^k都是1,之后都是奇数递增。
#include<stdio.h>
int main()
{
int n,tn,m;
while(scanf("%d",&n)>0)
{
m=1; tn=n;
while(tn>1)
{
m*=2; tn/=2;
}
printf("%d\n",2*(n-m)+1);
}
}

最新文章

  1. 【HDU】3853 LOOPS
  2. Effective Java 32 Use EnumSet instead of bit fields
  3. ejabberd常见配置说明
  4. 强连通分量(tarjan求强连通分量)
  5. 第一次JAVA基础考试后的反思
  6. Spring MVC视图层:thymeleaf vs. JSP
  7. 给Activity切换加入动画
  8. nodejs+websocket制作聊天室视频教程
  9. CSS3中only-child伪类选择器
  10. DirectX11 With Windows SDK--21 鼠标拾取
  11. 行业相关的webgl项目
  12. js方法用来获取路径传参上所带的参数
  13. python中和生成器协程相关的yield from之最详最强解释,一看就懂(四)
  14. Codeforces976E Well played! 【贪心】
  15. css易错点总结
  16. Java理论学时第三节。课后作业。
  17. this与$(this)对象
  18. BZOJ NOIP提高组十连测第一场
  19. 多目标跟踪方法:deep-sort
  20. [性能测试]:记录一次性能测试,nmon文件收集工具的小问题

热门文章

  1. Python+Selenium 自动化实现实例-模块化调用
  2. WordPress用户登录后根据不同的角色跳转到不同的页面处理
  3. 【PAT】1006. 换个格式输出整数 (15)
  4. c++ primer 4 数组和指针
  5. 解决 .net HttpClient 调用时出现的 &quot;A task was cancelled&quot; 错误
  6. 二叉排序树实现(C++封装)
  7. 开源IDS系列--snorby 2.6.2 undefined method `run_daily_report&#39; for Event:Class (NoMethodError)
  8. PHP库函数积累,持续更新
  9. Mybatis源码分析之插件的原理
  10. Unity 2D游戏开发教程之游戏精灵的开火状态