home *** CD-ROM | disk | FTP | other *** search
- Problem 15: Circular execution.
-
-
- You and your friends are suddenly rounded up into a circle. You are told
- that, starting from the head of the circle, THEY will count to M, execute
- that Mth person, close the circle, and repeat this process until just one
- person is left to escape. Given that there are N persons and that the
- rule is to execute every Mth person, you need to decide which position
- to take in the circle if you are to remain alive.
-
- Write a program that reads and computes, for four pairs of (M,N) values.
- For each pair, as your program executes (literally!), have it print out the
- identity of each person as he is eliminated. For example, with M = 7 and
- N = 11, the output would be: 7 3 11 9 8 10 2 6 1 4 5
- (showing 5 (the last guy in the list) surviving).
-
- There will be exactly four M,N pairs in the input datafile, two per line.
- M and N will each be less than or equal to 20.
- Such as:
- 7 11
- 9 13
- 13 15
- 7 14
-
- Note that there is NO requirement that M be less than N.
-
- Be careful that your output consists of exactly four lines.
-