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

建议使用的浏览器:

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

2984:A New Joseph Problem

题目描述

Newman and Bamboo are good friends. One day, Newman taught Bamboo the famous Joseph Problem: there are N persons numbered 1 to N standing round a circle. They stand clockwise according to their numbers (namely 1, 2, 3, 4, …, N). Then, starting from 1, the killer kills every 2nd person he counts until there is only one person left whose number is J(N). We can easily infer that J(1) = 1, J(5) = 3 and J(6) = 5. Bamboo finds this problem intriguing and starts thinking. Suddenly, he finds that if he continually uses J(N) to be the term in J, he can finally get a fixed number. For example, J(2) = 1, so J(J(2)) = 1, J(J(…J(2)…)) = 1. Newman agrees with Bamboo but Bamboo is not satisfied. Furthermore, Bamboo wants to know what the fixed number will be for a specific N. Can you help us?

输入解释

Only one line containing n (1 ≤ n ≤ 1010000).

输出解释

Only one line containing K such that J(J(J(JJ(N)…))) = K and J(K)=K.

输入样例
10
输出样例
3
提示

J(10) = 5, J(5) = 3, J(3) = 3.


该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2984

最后修改于 2020-10-29T06:49:10+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000 131072