#P8181. 「EZEC-11」Circle
「EZEC-11」Circle
Problem Description
There are people, numbered from to , sitting in a circle playing Josephus.
They count cyclically from to . Unlike the standard Josephus problem, everyone who does not count to will be eliminated, until only one person survives.
Let the survivor's number be . Define .
Given , compute , and output the result modulo .
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
One line contains three integers in order.
Output Format
For each test case:
Output one line with one integer, the result modulo .
4
2 1 4
3 3 7
8 12 64
2 1 1048976
6
17
1149
148359175
Hint
This problem uses bundled testcases.
- Subtask 1 (4 pts): , , .
- Subtask 2 (8 pts): , , .
- Subtask 3 (8 pts): .
- Subtask 4 (10 pts): .
- Subtask 5 (25 pts): , .
- Subtask 6 (45 pts): No special constraints.
For of the testdata, , , .
Translated by ChatGPT 5