程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> numbers- A New Joseph Problem

numbers- A New Joseph Problem

編輯:編程解疑
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

最佳回答:


http://www.acmerblog.com/POJ-2984-A-New-Joseph-Problem-blog-911.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved