Submit Address: http://poj.org/problem?id=1012 Joseph
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 52098 |
|
Accepted: 19839 |
Description
The Joseph ' s problem is notoriously known. For those who is familiar with the original Problem:from among n people, numbered 1, 2, ..., n, standing in circle Every mth is going to being executed and only the last remaining person would be saved. Joseph is smart enough to choose the position of the last remaining person, thus saving he life to give us the message a Bout the incident. For example if n = 6 and M = 5 then the people would be executed in the order 5, 4, 6, 2, 3 and 1 would be saved.
Suppose that there is k good guys and k bad guys. In the circle the first k is good guys and the last k bad guys. You had to determine such minimal m so all the bad guys would be executed before the first good guy.
Input
The input file consists of separate lines containing K. The last line in the input file contains 0. You can suppose that 0 < K < 14.
Output
The output file would consist of separate lines containing m corresponding to K in the input file.
Sample Input
340
Sample Output
530
View Code
The specific parsing and source code address: Turn from: http://www.cnblogs.com/yu-chao/archive/2011/05/29/2062276.html
POJ 1012--toseph