Easy30 pts
Manasa and Stones
Start at stone 0. Place n stones. Each stone = previous + a OR previous + b. Find all possible values for the last (n-th) stone, sorted ascending. Formula: If we use 'a' j times and 'b' (n-1-j) times, last stone = j×a + (n-1-j)×b. Try all j from 0 to n-1. Example: n=3, a=1, b=2 → j=0: 0+2+2=4, j=1: 0+1+2=3 or 0+2+1=3, j=2: 0+1+1=2 → Unique: [2,3,4]
Input
First line: t (test cases). Next t lines: each line has n a b (space-separated).
Output
For each test case, output the possible last stone values, space-separated, in ascending order.
Sample
2 3 1 2 4 10 100
Expected
2 3 4 30 120 210 300
Loading editor…
Output
No output yet. Run your code to see results.