1974 - I2P(II)2020_Yang_lab2 Scoreboard

Time

2020/03/27 13:20:00 2020/03/27 15:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12679 Ouo's problem

12679 - Ouo's problem   

Description

No story this time :D

There are N people standing in a circle, number from 1 ~ N clockwisely.
Starting from the first people.
Every round, they count from 1 ~ M clockwisely.
and the Mth person get out of the circle,
then the 2 people, who stand beside this person swap their position.
After the 2 people swap their positions,
the next round will start counting from the person who has a smaller number.
The game ends when there is only a person remain in the circle.

Given you N and M, tell the last person's number standing in the circle.

ouo.

For example, N=5 and M=2,
so there are 5 people standing in the circle at first:


Round  Circle (Clockwise)   Description
0          1->2->3->4->5   The number 2 get out of the circle, and the number 1, 3 swap their positions, and the next round starts from number 1 ( 1 < 3 )

1          3->1->4->5         Start from number 1, count 1->4, so the number 4 get out of the circle, and number 1, 5 swap their position, and the next round starts from number 1 ( 1 < 5 )

2          3->5->1               Start from number 1, count 1->3, so the number 3 get out of the circle, and number 1, 5 swap their position, and the next round starts from number 1 ( 1 < 5 )

3          1->5                     Start from number 1, count 1->5, so the number 5 get out of the circle

4          1                           Number 1 Win :D

Important Notifications:
0. This is a partial judge problem, you only need to implement some functions.
1. Since this is a partial judge problem, you need to download the following files, those files will be compiled with your submission code.
2. See the comments in the code carefully, it will help you a lot :D
3. Remember to 'include "function.h"' in your submission code
4. After downloading the partial judge codes, you can rename '12679.h' with 'function.h', rename '12679.c' with 'main.c', then name your file 'function.c'. Then you can compile these files with (1) A Codeblocks project. (2) Using command 'gcc main.c function.c', then run './a.out' on macOS, './a.exe' on Windows. Or any other ways.

5. Do not just swap the value of the node, 'val' is a constant value.

Input

Given 2 numbers N, M,
N is the number of people at the beginning,
M is the number to count each round.

1 <= N <= 21000
1 <= M <= 109

Output

Output contains only a line.

Output the last person's number that stands in the circle,
and a newline character after it.

Sample Input  Download

Sample Output  Download

Partial Judge Code

12679.c

Partial Judge Header

12679.h

Tags




Discuss