User:Spundun/Math/AP2

AP2
Arithmatic and geometric Progressions are 2 of the well known progressions in maths.

Arithmatic progression(AP) is a set in which the difference between 2 numbers in constant. for eg, 1,3,5,7,9 .... In this series the difference between 2 numbers is 2.

The task here is very simple indeed.

You will be given the 3rd term, 3rd last term and the sum of the series. You need print length of the series & the series.

Input

First line will contain a number indicating the number of test cases.

Each of the following t lines will have 3 number '3term' ,'3Lastterm' and 'sum'

3term - is the 3rd term in of the series and

3Lastterm - is the 3rd term in of the series and

sum - is the sum of the series.

Output

For each input of the test case, you need to print 2 lines.

fist line should have 1 value- number of terms in the series.

2nd line of the output should print the series numbers separated by single space.

Example

Input: 1 3 8 55

Output: 10 1 2 3 4 5 6 7 8 9 10

NOTE - In all the test cases all the series elements are positive integers. The series will have at least 7 elements. number of test cases <=100. All the numbers will fit in 64 bits(long long in C)

Solution
The series will be of $$ax+b$$ nature. Where $$1\le x \le N$$

The three numbers we have are

$$a(3)+b=\alpha (1)$$

$$a(N-2)+b=\beta (2)$$

$$\sum_{x=1}^Nax+b = a\frac{N^2+N}{2}+bN = \gamma (3)$$

Subtracting 1 from 2.

$$aN-5a=\beta-\alpha (4)$$

Subtracting 1 from 3.

$$a\frac{N^2+N}{2}+bN - 3aN - bN = \gamma - \alpha N (5)$$

Taking 4 further.

$$a = \frac{\beta-\alpha}{N-5} (6)$$

Simplifying 5

$$a\frac{N(N-5)}{2} = \gamma - \alpha N$$

Substituting a

$$\frac{\beta-\alpha}{N-5}\frac{N(N-5)}{2}= \gamma - \alpha N$$

$$\frac{N(\beta - \alpha)}{2} = \gamma - N\alpha$$

$$N\frac{\beta+alpha}{2}=\gamma$$

$$N = \frac{2\gamma}{\beta+\alpha}$$

$$a = \frac{\beta-\alpha}{N-5} $$

$$b = \alpha - 3a$$