#C3285. Array Generation with Divisible Differences

    ID: 46695 Type: Default 1000ms 256MiB

Array Generation with Divisible Differences

Array Generation with Divisible Differences

You are given two positive integers, N and M.
Your task is to generate an array of length N such that the absolute difference between any two consecutive elements is divisible by M.
One valid construction is to generate the array in the form:

$a_i = 1 + (i-1) \times M$, for \(1 \leq i \leq N\).

This guarantees that for any consecutive elements \(a_i\) and \(a_{i+1}\), the difference is \(M\), which is clearly divisible by M.

You need to handle multiple test cases in a single execution.

inputFormat

The first line of input contains a single integer T denoting the number of test cases. Each of the following T lines contains two space-separated integers N and M - the length of the array and the divisor for the consecutive differences, respectively.

For example:

5
1 2
2 3
3 1
4 2
5 5

outputFormat

For each test case, output a single line containing N space-separated integers, representing the generated array which satisfies the condition that the difference between any two consecutive elements is divisible by M.

For the sample input above, the output should be:

1
1 4
1 2 3
1 3 5 7
1 6 11 16 21
## sample
5
1 2
2 3
3 1
4 2
5 5
1

1 4 1 2 3 1 3 5 7 1 6 11 16 21

</p>