Dare not die-Joseph Deformation

Source: Internet
Author: User
Don't dare to die Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ Description

When it comes to "death squad", don't introduce the movie to me, because there is such a program design question in the data structure. The original question is as follows:

There are m death squads who want to blow up an enemy's bunker. No one wants to go. The length of the platoon decides which fighters to execute the task by means of the number of rounds. If the previous warrior fails to complete the task, send another warrior. Now we have a code for each warrior. Everyone is sitting in a circle and counting it from a warrior. When the number is 5, the corresponding warrior executes the task, this warrior will not participate in the next round of counting. If the warrior does not complete the task, count from the next one. When the number of soldiers reaches 5th, the warrior proceeds to execute the task. And so on until the task is completed.

This question was originally called "death squad ". "No one wants to go." I think this problem can only be called "No death ". Today, we are about to solve this problem. Let's assume that the length is 1. According to the above introduction, the number of soldiers starting from 1 and counting to 5 will execute the task. What is the length of the platoon to execute the task?

Input

The input includes multi-test data. Each row has an integer m (0 <= m <= 10000) (number of death squads). If M = 0, the input ends without processing.

Output

Output an integer N, indicating that the length is the nth to execute the task.

Sample Input
9
6
223
0
Sample output
2
6
132
Application of Joseph's Problem

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.