Repeated Josephus
Input: standard input
Output: standard output
Time Limit: 1 second
Example with n = 5:
After the first elimination round, the survivor is person 3. Because
this is is not the last person in the circle, a new elimination round
with 3 people is started.
Now person 3 survives, so we can stop.
Input
The first
line in the input file is an integer representing
the number of test cases. Each of the test cases follows below. Each
test case consists of an integer representing n ( 0 < n ≤
30000 ).
Output
For each test case, print the serial number of the case, a colon, an space, total number of repetitions (the number of times the elimination process is done after the initial elimination round with n people), an space and the position of the survivor at last. Check the sample input & output.
Sample Input
2
13
23403
Sample
Output
Case 1: 2 7
Case 2: 8 1023
Problem setter: Anupam Bhattacharjee, CSE, BUET
Thanks to Adrian for alternate solution.
"~~ Simple
matters in the world need not always be simple ~~