Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that any two consecutive stones' numbers differ by one of two values. Legend has it that there is a treasure trove at the end of the trail. If Manasa can guess the value of the last stone, the treasure will be hers.
She finds stones and their differences are or . We know she starts with a stone not included in her count. The permutations of differences for the two stones are or . Looking at each scenario, stones might have or on them. The last stone might have any of , or on its face.
Compute all possible numbers that might occur on the last stone given a starting stone with a on it, a number of additional stones found, and the possible differences between consecutive stones. Order the list ascending.
Complete the stones function in the editor below.
stones has the following parameter(s):
int n: the number of non-zero stones
int a: one possible integer difference
int b: another possible integer difference
int: all possible values of the last stone, sorted ascending
The first line contains an integer , the number of test cases.
Each test case contains lines:
- The first line contains , the number of non-zero stones found.
- The second line contains , one possible difference
- The third line contains , the other possible difference.
2 T = 2 (test cases)
3 n = 3 (test case 1)
1 a = 1
2 b = 2
4 n = 4 (test case 2)
10 a = 10
100 b = 100
2 3 4
30 120 210 300
With differences 1 and 2, all possible series for the first test case are given below:
Hence the answer 2 3 4.
With differences 10 and 100, all possible series for the second test case are the following: