The last cracker
All submissions for this problem are available.
Ram has N different crackers. These crackers are very special, each of them can fire infinite number of fire-balls. Ram made an arrangement with those N crackers. If the spark is currently with the i'th cracker, it will first fire a fire-ball, and then it will pass the spark to the (i+1)'th cracker. Note that the N'th cracker will pass spark to the 1'st cracker. Ram initially placed the spark at the a'th cracker. However the spark will get exhausted after M passes, that is, it gets off during M+1'th pass. Ram want to know which cracker will fire the last fire-ball before spark goes off. Write a program to print this answer.
The first line of the input contains an integer T denoting the number of test cases.
Following T lines describe the test cases, one per line.
Each line contains 3 integers, N, a and M.
For each test case output one line, which contains the required answer.
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000
- 0 ≤ M ≤ 1000
- 1 ≤ a ≤ N
Input: 3 5 1 3 5 1 5 5 1 19 Output: 4 1 5
Test case #1:
Spark is initially at the 1'st cracker. It fires a fire-ball and passes spark to the 2'nd cracker. The 2'nd cracker fires a fire-ball and passes the spark to the 3'rd cracker. The 3rd cracker fires a fire-ball and passes spark to the 4th cracker. The 4th cracker fires a fire-ball and passes the spark to the 5'th cracker, however, we already made 3 passes and this is 4th pass, so spark gets off. The last cracker to fire a fire-ball is the 4'th cracker.
Test case #2:
Spark is initially at the 1'st cracker. It fires a fire-ball and passes spark to the 2'nd cracker. After the 4'th pass, the spark is with the 5'th cracker. The 5'th cracker fires a fire-ball and passes it to the 1'st cracker (Read the statement carefully, the N'th cracker passes spark to the 1'st cracker). The 1'st cracker fires the fire-ball and passes to the 2'nd cracker, spark gets exhausted during this pass. So the last cracker to fire was the 1'st.
|Tags||acmkg14r, admin, cakewalk, programming|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.