当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5643:King's Game

题目描述
In order to remember history, King plans to play losephus problem in the parade gap.He calls $n (1\le n\le 5000)$ soldiers, counterclockwise in a circle, in label $1, 2, 3... n$.

The first round, the first person with label $1$ counts off, and the man who report number $1$ is out.

The second round, the next person of the person who is out in the last round counts off, and the man who report number $2$ is out.

The third round, the next person of the person who is out in the last round counts off, and the person who report number $3$ is out.



The N - 1 round, the next person of the person who is out in the last round counts off, and the person who report number $n-1$ is out.

And the last man is survivor. Do you know the label of the survivor?
输入解释
The first line contains a number $T(0 < T \le 5000)$, the number of the testcases.

For each test case, there are only one line, containing one integer $n$, representing the number of players.
输出解释
Output exactly $T$ lines. For each test case, print the label of the survivor.
输入样例
2
2
3
输出样例
2
2

Hint:
For test case #1:the man who report number $1$ is the man with label $1$, so the man with label $2$ is survivor.

For test case #1:the man who report number $1$ is the man with label $1$, so the man with label 1 is out. Again the the man with label 2 counts $1$,  the man with label $3$ counts $2$, so the man who report number $2$ is the man with label $3$. At last the man with label $2$ is survivor.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #75

源链接: HDU-5643

最后修改于 2020-10-25T23:24:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)