POJ 1012--toseph

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.