编程介的小学生 2016-12-29 05:00 采纳率: 20.5%
浏览 886
已采纳

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(J…J(N)…))) = K and J(K)=K.

样例输入:

10
样例输出:

3

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-29 16:57
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包