-->
当前位置:首页 > 题库

PROGRAMMING:josephus problem

Luz5年前 (2021-05-10)题库385
###Task description
```
Joseph's problem: there are n monkeys in a circle clockwise to choose the king (numbered from 1 to n). They count from No. 1 until m. The monkeys who count to m quit the circle, and the remaining monkeys count from 1. In this way, until there is only one monkey left in the circle, the monkey is the monkey king. Program to input n, m and output the number of the last Monkey King.
```
###Input format:
```
Each line is two integers separated by spaces, the first is n and the second is m (0 < m, n < = 300). The last line is:
0 0
```
###Output format:
```
For each line of input data (except the last line), the output data is also a line, that is, the number of the last Monkey King
```
###Input example:
```in
6 2
12 4
8 3
0 0
```
###Output example:
```out
five
one
seven
```
###Title Source
Selected from openjudge website, online address: bailian.openjudge.cn/practice/2746/







answer:If there is no answer, please comment